ATMEGA8 沙盘控制程序
文件大小: 320k
源码售价: 10 个金币 积分规则     积分充值
资源说明:ATMEGA8 18路沙盘控制程序 void uart_init(void) //串口0初始化 {UCSR0B=0x00; //disable while setting baud rate UCSR0A=0B00000000; //Bit1为1则倍速发送 U2X=0 UCSR0C=0x06; //B00000110 //奇偶模式无,八位数据位,一位停止位 UBRR0L=71; //B00011001波特率:4800 Bps UBRR0H=0x00; //误差率:0.156% UCSR0B=0x98; recstate = recStart; } void putchar(unsigned char c) //串口0发送字符 { while(!(UCSR0A&(1<< UDRE0))); //while(!(UCSR0A&32;)); 在此如何理解? UDR0=c; } void putstr(unsigned char *s) //串口0发送字符串 { while(*s) { putchar(*s); s++; } } #pragma interrupt_handler Uartms_Rx_Interrupt:iv_USART0_RX /*-------------------------------------------------- 功能:短信接收中断服务 入口:无 出口:无 --------------------------------------------------*/ void Uartms_Rx_Interrupt(void) { unsigned char rxdat; static crctemp,conter = 0; rxdat=UDR0; switch(recstate) { case recStart: if(rxdat == 0xaa) { recstate = recLong; crctemp = 0; } break; case recLong: COMMURcv.inflong = rxdat; recstate = recCMD; break; case recCMD: COMMURcv.infCMD = rxdat; recstate = recData; break; case recData: if(rxdat == 0xaa) { COMMURcv.recOK = TRUE; recstate = recStart; } recstate = recStart; break; default : break; } } bool sendchar(unsigned char sendchar) { unsigned char temp; temp = sendchar>>4; if(temp<10) { UartmsSnd.buff[0] = temp+'0'; } else { UartmsSnd.buff[0] = temp+'A'-10; } temp = sendchar&0x0f; if(temp<10) { UartmsSnd.buff[1] = temp+'0'; } else { UartmsSnd.buff[1] = temp+'A'-10; } UartmsSnd.buff[2] = ' '; UartmsSnd.buff[3] = 0; putstr(UartmsSnd.buff); return TRUE; } bool sendchar_enter(unsigned char sendchar) { unsigned char temp; unsigned char uart_buf[16]; temp = sendchar/0x10; if(temp<10) { uart_buf[0] = temp+'0'; } else { uart_buf[0] = temp+'A'-10; } temp = sendchar%0x10; if(temp<10) { uart_buf[1] = temp+'0'; } else { uart_buf[1] = temp+'A'-10; } uart_buf[2] = '\n'; uart_buf[3] = '\r'; uart_buf[4] = 0; putstr(uart_buf); return TRUE; }
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。