#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; //发送端设为P4.1
sbit newRXD = P4^2; //接收端设为p4.2
void Delayxms(unsigned char i)
{
while(--i)
{
_nop_();
}
}
void UartInit() //串口初始化
{TMOD= 0x02; //定时器0方式2
TH0 = 0xFD; //9600波特率
TL0 = TH0;
TR0 = 0; //在发送或接受才开始使用
TF0 = 0;
ET0 = 1; //允许允许定时器0中断
EA=1; //中断允许
}
void WByte(uint input)
{
//发送启始位
uchar j=8;
newTXD=(bit)0; //发送8位数据位
while(j--)
{
newTXD=(bit)(input&0x01); //先传低位
input=input>>1;
}
//发送校验位(无)
//发送结束位
newTXD=(bit)1;
}
void Sendata()
{
for(i=0;i<sizeof(zhiling);i++)//外层循环,遍历数组
{
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();
}
}
|