給你改了一下試試。
- #include "stc15f2k60s2.h"
- #include "lcd.h"
- #include <stdio.h>
- #include <string.h>
- #include "intrins.h"
- #define uint unsigned int
- #define uchar unsigned char
- int i;
- uint code zhiling[ ]={0xDD,0xA5,0x03,0x00,0xFF,0xFD,0x77};
- char xdata char_U[50]; //總電壓
- char xdata char_I[50]; //總電流
- char xdata char_EXT[50]; //電池溫度
- void display(); //屏幕顯示
- sbit newTXD = P4^1; //發(fā)送端設(shè)為P4.1
- sbit newRXD = P4^2; //接收端設(shè)為p4.2
- void Delayxms(unsigned char i)
- {
- while(--i)
- {
- _nop_();
- }
- }
- void UartInit() //串口初始化
- {TMOD= 0x02; //定時器0方式2
- TH0 = 0xFD; //9600波特率
- TL0 = TH0;
- TR0 = 0; //在發(fā)送或接受才開始使用
- TF0 = 0;
- ET0 = 1; //允許允許定時器0中斷
- EA=1; //中斷允許
- }
- void WByte(uint input)
- {
- //發(fā)送啟始位
- uchar j=8;
- newTXD=(bit)0; //發(fā)送8位數(shù)據(jù)位
- while(j--)
- {
- newTXD=(bit)(input&0x01); //先傳低位
- input=input>>1;
- Delayxms(96); //延時 104us
- }
- //發(fā)送校驗位(無)
- //發(fā)送結(jié)束位
- newTXD=(bit)1;
- }
- void Sendata()
- {
- for(i=0;i<sizeof(zhiling);i++)//外層循環(huán),遍歷數(shù)組
- {
- WByte(zhiling[i]);
- }
- }
- /*
- void display()
- {
- display_graphic_16x16(1,1,0,zong16);
- display_graphic_16x16(1,17,0,dian16);
- display_graphic_16x16(1,33,0,ya16);
- display_string_8x16(1,49,0,":"); //總電壓
- display_graphic_16x16(3,1,0,zong16);
- display_graphic_16x16(3,17,0,dian16);
- display_graphic_16x16(3,33,0,liu16);
- display_string_8x16(3,49,0,":"); //總電流
- display_graphic_16x16(5,1,0,sheng16);
- display_graphic_16x16(5,17,0,yu16);
- display_graphic_16x16(5,33,0,dian16);
- display_graphic_16x16(5,49,0,liang16);
- display_string_8x16(5,65,0,":"); //剩余電量
- display_graphic_16x16(7,1,0,dian16);
- display_graphic_16x16(7,17,0,chi16);
- display_graphic_16x16(7,33,0,wen16);
- display_graphic_16x16(7,49,0,du16);
- display_string_8x16(7,65,0,":"); //電池溫度
- }
- */
- void main()
- {
- UartInit();
- while(1)
- {
- Sendata();
- }
- }
復(fù)制代碼 |