#include <c8051f020.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit SPEAKER=P3^3;
sbit SLEEP=P3^1;
sbit WX_RST=P3^2;
unsigned char warning_flag;
unsigned char chaomx_flag;
unsigned char flag;
unsigned char k;
unsigned int idata c_timer0; //計(jì)時(shí)器
unsigned char data I2C_RAM[16]; //I2C數(shù)據(jù)交換RAM
unsigned char data bat_count; //電池采樣計(jì)數(shù)
unsigned char code *pointer;
unsigned char idata uart0_se; //uart0口接收開(kāi)始同步字和結(jié)束符個(gè)數(shù)
unsigned char idata uart0_num; //uart0口接收、發(fā)送字符個(gè)數(shù)
unsigned char idata battery_volt; //電池電壓 battery_volt=60*(battery_ad÷battery_base)
unsigned char idata battery_base[3]; //電池標(biāo)稱ad值和標(biāo)稱時(shí)的電壓
unsigned int idata battery_ad; //電池當(dāng)前ad值
unsigned int idata battery_sampling[4]; //電池采樣周期瞬時(shí)值
void main(void)
{
//*************************************************************
//******系統(tǒng)初始化*********************************************
/*初始化------------------------------*/
P1MDIN=0xFF;
EMI0CF=0x03;
XBR0=0x04; //00000100B /* UART0*/
// XBR1=0x04; //00000100B /* INT0 */
XBR2=0x42; //01000010B /* 弱上拉允許,允許交叉開(kāi)關(guān),UART1不連到端口 */
//UART0初始化
TL1=0xfd;
TH1=0xfd; //定時(shí)器T1裝載值 FDH(9600), FAH(4800), F4H(2400), E8(1200)
SCON0=0x50; //設(shè)串口UART0為模式1(用于無(wú)線通信或PC通信) (用T1)
SCON1=0x50;
//定時(shí)器設(shè)定
CKCON=0x00; //T0,T1,T2,T4使用SYSCLK的12分頻
T2CON=0x04; //T1為UART0串口波特率發(fā)生器,啟動(dòng)T2
TMOD=0x21; //T0為定時(shí)方式1,T1為8位自動(dòng)裝載為UART0串口波特率發(fā)生器
TR1=1; //啟動(dòng)T1
//DAC0設(shè)置
P0MDOUT=0x01; //00000001B /*P0配置*/
P1MDOUT=0xff; /*P1*/
P2MDOUT=0xff; /*P2*/
P3MDOUT = 0xff; //11111111B P3口配置 /*各個(gè)端口輸入時(shí)配置為漏極開(kāi)路,輸出時(shí)配置為推挽方式*/
P74OUT=0x00;
P4=P4&0xd3; /*ALE=0,A16=0(P4.3),LCDE=0(P4.2)*/
WDTCN=0xde; /*暫時(shí)禁止看門狗定時(shí)器*/
WDTCN=0xad;
SCON1=SCON1&0xfc; //清TI1,RI1
//外部中斷設(shè)置
IE0=0; /* 清中斷標(biāo)志 */
ES0=1; //開(kāi)放串口UART0中斷
EA=1; //開(kāi)總中斷
AMX0SL=0x07;
//初始化
P5=P5&0xfd; //開(kāi)機(jī)點(diǎn)亮工作燈
while (1);
}
void uart0_rt(void) interrupt 4
{
k=0;
if( _testbit_(RI0))
{
k=SBUF0;
}
}
程序如上,不明白為啥接收數(shù)據(jù)總是不對(duì),能接收。。。
|