当前位置: 首页 > wzjs >正文

纯html网站模板物流网信息平台

纯html网站模板,物流网信息平台,芜湖百度seo,wordpress企业免费主题是什么意思转载请注明出处&#xff1a;小锋学长生活大爆炸[xfxuezhagn.cn] 如果本文帮助到了你&#xff0c;欢迎[点赞、收藏、关注]哦~ 没想到这么老&#xff0c;很多代码都不能用&#xff0c;修了好久。。。 TinySoftwareSerial.cpp #include <stdlib.h> #include <stdio.h&g…

转载请注明出处:小锋学长生活大爆炸[xfxuezhagn.cn]

如果本文帮助到了你,欢迎[点赞、收藏、关注]哦~


没想到这么老,很多代码都不能用,修了好久。。。

TinySoftwareSerial.cpp

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>#include "Arduino.h"
#include "wiring_private.h"#if USE_SOFTWARE_SERIAL
#include "TinySoftwareSerial.h"extern "C"{
uint8_t getch() {uint8_t ch = 0;__asm__ __volatile__ ("   rcall uartDelay\n"          // Get to 0.25 of start bit (our baud is too fast, so give room to correct)"1: rcall uartDelay\n"              // Wait 0.25 bit period"   rcall uartDelay\n"              // Wait 0.25 bit period"   rcall uartDelay\n"              // Wait 0.25 bit period"   rcall uartDelay\n"              // Wait 0.25 bit period"   clc\n""   in r23,%[pin]\n""   and r23, %[mask]\n""   breq 2f\n""   sec\n""2: ror   %0\n""   dec   %[count]\n""   breq  3f\n""   rjmp  1b\n""3: rcall uartDelay\n"              // Wait 0.25 bit period"   rcall uartDelay\n"              // Wait 0.25 bit period:"=r" (ch):"0" ((uint8_t)0),[count] "r" ((uint8_t)8),[pin] "I" (_SFR_IO_ADDR(ANALOG_COMP_PIN)),[mask] "r" (Serial._rxmask):"r23","r24","r25");return ch;
}void uartDelay() {__asm__ __volatile__ ("mov r25,%[count]\n""1:dec r25\n""brne 1b\n""ret\n"::[count] "r" ((uint8_t)Serial._delayCount));
}#if !defined (ANALOG_COMP_vect) && defined(ANA_COMP_vect)
//rename the vector so we can use it.#define ANALOG_COMP_vect ANA_COMP_vect
#elif !defined (ANALOG_COMP_vect)#error Tiny Software Serial cannot find the Analog comparator interrupt vector!
#endif
ISR(ANALOG_COMP_vect){char ch = getch(); //read in the character softwarily - I know its not a word, but it sounded cool, so you know what: #define softwarily 1store_char(ch, Serial._rx_buffer);sbi(ACSR,ACI); //clear the flag.
}}
soft_ring_buffer rx_buffer  =  { { 0 }, 0, 0 };// Constructor TinySoftwareSerial::TinySoftwareSerial(soft_ring_buffer *rx_buffer, uint8_t txBit, uint8_t rxBit)
{_rx_buffer = rx_buffer;_rxmask = _BV(rxBit);_txmask = _BV(txBit);_txunmask = ~_txmask;_delayCount = 0;
}// Public Methods //
void TinySoftwareSerial::setTxBit(uint8_t txbit)
{_txmask=_BV(txbit);_txunmask=~txbit;
}void TinySoftwareSerial::begin(long baud)
{long tempDelay = (((F_CPU/baud)-39)/12);if ((tempDelay > 255) || (tempDelay <= 0)){end(); //Cannot start as it would screw up uartDelay().}_delayCount = (uint8_t)tempDelay;cbi(ACSR,ACIE);  //turn off the comparator interrupt to allow change of ACD
#ifdef ACBGsbi(ACSR,ACBG); //enable the internal bandgap reference - used instead of AIN0 to allow it to be used for TX.
#endifcbi(ACSR,ACD);  //turn on the comparator for RX
#ifdef ACICcbi(ACSR,ACIC);  //prevent the comparator from affecting timer1 - just to be safe.
#endifsbi(ACSR,ACIS1);  //interrupt on rising edge (this means RX has gone from Mark state to Start bit state).sbi(ACSR,ACIS0);//Setup the pins in case someone messed with them.ANALOG_COMP_DDR &= ~_rxmask; //set RX to an inputANALOG_COMP_PORT |= _rxmask; //enable pullup on RX pin - to prevent accidental interrupt triggers.ANALOG_COMP_DDR |= _txmask; //set TX to an output.ANALOG_COMP_PORT |= _txmask; //set TX pin highsbi(ACSR,ACI); //clear the flag.sbi(ACSR,ACIE);  //turn on the comparator interrupt to allow us to use it for RX
#ifdef ACSRBACSRB = 0; //Use AIN0 as +, AIN1 as -, no hysteresis - just like ones without this register.
#endif
}void TinySoftwareSerial::end()
{sbi(ACSR,ACI); //clear the flag.cbi(ACSR,ACIE);  //turn off the comparator interrupt to allow change of ACD, and because it needs to be turned off now too!
#ifdef ACBGcbi(ACSR,ACBG); //disable the bandgap reference
#endifsbi(ACSR,ACD);  //turn off the comparator to save power_delayCount = 0;_rx_buffer->head = _rx_buffer->tail;
}int TinySoftwareSerial::available(void)
{return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE;
}void store_char(unsigned char c, soft_ring_buffer *buffer)
{int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;// if we should be storing the received character into the location// just before the tail (meaning that the head would advance to the// current location of the tail), we're about to overflow the buffer// and so we don't write the character or advance the head.if (i != buffer->tail) {buffer->buffer[buffer->head] = c;buffer->head = i;}
}int TinySoftwareSerial::peek(void)
{if (_rx_buffer->head == _rx_buffer->tail) {return -1;} else {return _rx_buffer->buffer[_rx_buffer->tail];}
}int TinySoftwareSerial::read(void)
{// if the head isn't ahead of the tail, we don't have any charactersif (_rx_buffer->head == _rx_buffer->tail) {return -1;} else {unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];_rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;return c;}
}size_t TinySoftwareSerial::write(uint8_t ch)
{uint8_t oldSREG = SREG;cli(); //Prevent interrupts from breaking the transmission. Note: TinySoftwareSerial is half duplex.//it can either receive or send, not both (because receiving requires an interrupt and would stall transmission__asm__ __volatile__ ("   com %[ch]             \n" // ones complement, carry set"   sec                   \n""1: brcc 2f               \n""   in r23,%[uartPort]    \n""   and r23,%[uartUnmask] \n""   out %[uartPort],r23   \n""   rjmp 3f               \n""2: in r23,%[uartPort]    \n""   or r23,%[uartMask]    \n""   out %[uartPort],r23   \n""   nop                   \n""3: rcall uartDelay       \n""   rcall uartDelay       \n""   rcall uartDelay       \n""   rcall uartDelay       \n""   lsr %[ch]             \n""   dec %[count]          \n""   brne 1b               \n"::[ch] "r" (ch),[count] "r" ((uint8_t)10),[uartPort] "I" (_SFR_IO_ADDR(ANALOG_COMP_PORT)),[uartMask] "r" (_txmask),[uartUnmask] "r" (_txunmask): "r23","r24","r25");SREG = oldSREG;return 1;
}void TinySoftwareSerial::flush()
{}TinySoftwareSerial::operator bool() {return true;
}// Preinstantiate Objects //
#ifndef ANALOG_COMP_DDR
#error Please define ANALOG_COMP_DDR in the pins_arduino.h file!
#endif#ifndef ANALOG_COMP_PORT
#error Please define ANALOG_COMP_PORT in the pins_arduino.h file!
#endif#ifndef ANALOG_COMP_PIN
#error Please define ANALOG_COMP_PIN in the pins_arduino.h file!
#endif#ifndef ANALOG_COMP_AIN0_BIT
#error Please define ANALOG_COMP_AIN0_BIT in the pins_arduino.h file!
#endif#ifndef ANALOG_COMP_AIN1_BIT
#error Please define ANALOG_COMP_AIN1_BIT in the pins_arduino.h file!
#endifTinySoftwareSerial Serial(&rx_buffer, ANALOG_COMP_AIN0_BIT, ANALOG_COMP_AIN1_BIT);#endif // whole file

TinySoftwareSerial.h

#if USE_SOFTWARE_SERIAL
#ifndef TinySoftwareSerial_h
#define TinySoftwareSerial_h
#include <inttypes.h>
#include "Stream.h"#if !defined(ACSR) && defined(ACSRA)
#define ACSR ACSRA
#endif#if (RAMEND < 250)#define SERIAL_BUFFER_SIZE 8
#elif (RAMEND < 500)#define SERIAL_BUFFER_SIZE 16
#elif (RAMEND < 1000)#define SERIAL_BUFFER_SIZE 32
#else#define SERIAL_BUFFER_SIZE 128
#endif
struct soft_ring_buffer
{volatile unsigned char buffer[SERIAL_BUFFER_SIZE];volatile int head;volatile int tail;
};extern "C"{void uartDelay() __attribute__ ((naked,used)); //used attribute needed to prevent LTO from throwing it out.uint8_t getch();void store_char(unsigned char c, soft_ring_buffer *buffer);
}class TinySoftwareSerial : public Stream
{public: //should be private but needed by extern "C" {} functions.uint8_t _rxmask;uint8_t _txmask;uint8_t _txunmask;soft_ring_buffer *_rx_buffer;uint8_t _delayCount;public:TinySoftwareSerial(soft_ring_buffer *rx_buffer, uint8_t txBit, uint8_t rxBit);void begin(long);void setTxBit(uint8_t);void end();virtual int available(void);virtual int peek(void);virtual int read(void);virtual void flush(void);virtual size_t write(uint8_t);using Print::write; // pull in write(str) and write(buf, size) from Printoperator bool();
};#if (!defined(UBRRH) && !defined(UBRR0H)) || USE_SOFTWARE_SERIALextern TinySoftwareSerial Serial;
#endif//extern void putch(uint8_t);
#endif
#endif

pins_arduino.h

#ifndef Pins_Arduino_h
#define Pins_Arduino_h#include <avr/pgmspace.h>#include "core_build_options.h"//WARNING, if using software, TX is on AIN0, RX is on AIN1. Comparator is favoured to use its interrupt for the RX pin.
#define USE_SOFTWARE_SERIAL           1
//Please define the port on which the analog comparator is found.
#define ANALOG_COMP_DDR               DDRB
#define ANALOG_COMP_PORT              PORTB
#define ANALOG_COMP_PIN               PINB
#define ANALOG_COMP_AIN0_BIT          0
#define ANALOG_COMP_AIN1_BIT          1#if defined( __AVR_ATtinyX313__ )
#define PORT_A_ID 1
#define PORT_B_ID 2
#define PORT_D_ID 4
#endif#if defined( __AVR_ATtinyX4__ )
#define PORT_A_ID 1
#define PORT_B_ID 2
#endif#if defined( __AVR_ATtinyX5__ )
#define PORT_B_ID 1
#endif#define NOT_A_PIN 0
#define NOT_A_PORT 0#define NOT_ON_TIMER 0
#define TIMER0A 1
#define TIMER0B 2
#define TIMER1A 3
#define TIMER1B 4//changed it to uint16_t to uint8_t
extern const uint8_t PROGMEM port_to_mode_PGM[];
extern const uint8_t PROGMEM port_to_input_PGM[];
extern const uint8_t PROGMEM port_to_output_PGM[];
extern const uint8_t PROGMEM port_to_pcmask_PGM[];extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
// 
// These perform slightly better as macros compared to inline functions
//
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
// in the following lines modified pgm_read_word in pgm_read_byte, word doesn't work on attiny45
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_mode_PGM + (P))) )
#define portPcMaskRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_pcmask_PGM + (P))) )#if defined(__AVR_ATtinyX5__)
#define digitalPinToPCICR(p)    (((p) >= 0 && (p) <= 5) ? (&GIMSK) : ((uint8_t *)NULL))
#define digitalPinToPCICRbit(p) (PCIE)
#define digitalPinToPCMSK(p)    (((p) >= 0 && (p) <= 5) ? (&PCMSK) : ((uint8_t *)NULL))
#define digitalPinToPCMSKbit(p) (p)
#endif#if defined(__AVR_ATtinyX4__)
#define digitalPinToPCICR(p)    (((p) >= 0 && (p) <= 10) ? (&GIMSK) : ((uint8_t *)NULL))
#define digitalPinToPCICRbit(p) (((p) <= 2) ? PCIE1 : PCIE0)
#define digitalPinToPCMSK(p)    (((p) <= 2) ? (&PCMSK1) : (((p) <= 10) ? (&PCMSK0) : ((uint8_t *)NULL)))
#define digitalPinToPCMSKbit(p) (((p) <= 2) ? (p) : (10 - (p)))
#endif#if defined(__AVR_ATtiny4313__)
#define digitalPinToPCX(p,s1,s2,s3,s4,s5) \(((p) >= 0) \? (((p) <=  1) ? (s1)  /*  0 -  1  ==>  D0 - D1 */  \: (((p) <=  3) ? (s2)  /*  2 -  3  ==>  A1 - A0 */  \: (((p) <=  8) ? (s3)  /*  4 -  8  ==>  D2 - D6 */  \: (((p) <= 16) ? (s4)  /*  9 - 16  ==>  B0 - B7 */  \: (s5))))) \: (s5))
//                                                   s1 D     s2 A     s3 D     s4 B
#define digitalPinToPCICR(p)    digitalPinToPCX( p, &GIMSK,  &GIMSK,  &GIMSK,  &GIMSK,  NULL )
#define digitalPinToPCICRbit(p) digitalPinToPCX( p, PCIE2,   PCIE1,   PCIE2,   PCIE0,   0    )
#define digitalPinToPCMSK(p)    digitalPinToPCX( p, &PCMSK2, &PCMSK1, &PCMSK2, &PCMSK0, NULL )
#define digitalPinToPCMSKbit(p) digitalPinToPCX( p, p,       3-p,     p-2,     p-9,     0    )
#endif#endif

实测效果


文章转载自:

http://YUNgZLe6.yhLjc.cn
http://5tXzJbtC.yhLjc.cn
http://aipnmeT7.yhLjc.cn
http://3THzlUE6.yhLjc.cn
http://JstXkXub.yhLjc.cn
http://B9VwTSNF.yhLjc.cn
http://BFOLk6Wf.yhLjc.cn
http://CoCP4Dq0.yhLjc.cn
http://rnOPH6ME.yhLjc.cn
http://HwYZMcD8.yhLjc.cn
http://SOeFiWIF.yhLjc.cn
http://QMtj387P.yhLjc.cn
http://q6UohSIv.yhLjc.cn
http://aOq0vkXT.yhLjc.cn
http://6fX4tS57.yhLjc.cn
http://JfTBiKVG.yhLjc.cn
http://cvSTmMlH.yhLjc.cn
http://z5IAFymv.yhLjc.cn
http://rrHPbG76.yhLjc.cn
http://r0b1sPJo.yhLjc.cn
http://hkG6pDFt.yhLjc.cn
http://ykADMUec.yhLjc.cn
http://8DSxbfGo.yhLjc.cn
http://IhhQ1JcN.yhLjc.cn
http://GF4CekLS.yhLjc.cn
http://6uvZEyJz.yhLjc.cn
http://4faDWe1i.yhLjc.cn
http://VGPMZYTR.yhLjc.cn
http://qsj6hP5b.yhLjc.cn
http://SkcApdKg.yhLjc.cn
http://www.dtcms.com/wzjs/780512.html

相关文章:

  • 安全狗网站白名单指什么知名网站建设在哪里
  • 怎么查网站是不是百度做的广州城乡建设局
  • 网站建设冫金手指谷哥十四网店推广的目的有哪些
  • 智能建站系统开发忘记网站后台账号
  • 网站建设类论文银川网站建设怎么样
  • 做养生的网站多吗wordpress客户管理
  • 郑州哪有做网站的有哪些做平面设计好的网站
  • 做兼职用什么网站最好设计展厅的公司
  • 做视频网站服务器要求吗企业vi设计一整套
  • 吉林省延边州建设局网站室内装修装饰设计培训班
  • 想做外贸做哪些网站2021能看的网站不要app贴吧
  • 怎么样申请网站上海建设工程施工许可证查询网站6
  • 建设部二级结构工程师注销网站做网站租用服务器
  • 成都网站建设新网创想南宁商城网站建设
  • 网站建设设计制作外包旺道网站优化
  • 网站定制开发特点深圳网页制作培训课程价格
  • 局机关门户网站建设情况汇报上海黄浦区网站建设
  • 怎么让付费网站免费网站用什么程序做的
  • 网站该怎么找到网站开发重点难点分析
  • 网站建设365动漫制作技术专业
  • 广州联享品牌网站建设Spring做网站和什么
  • 手机手机网站开发做网站卖广告挣几百万
  • 百度网站html验证公众号网页怎么制作
  • 百度做网站多少钱能做广宁县住房建设局网站
  • 个人 建设图片分享网站网站没有备案信息该怎么做
  • 做程序题的国外网站无锡网络科技有限公司
  • 腾讯网站建设专家gif图片制作器
  • 商务网站建设总结长安公司网站建设
  • 上海高端建站公司在百度怎么推广
  • 聊城网站开发2021年中国关键词