#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; //计时器
unsigned char data I2C_RAM[16]; //I2C数据交换RAM
unsigned char data bat_count; //电池采样计数
unsigned char code *pointer;
unsigned char idata uart0_se; //uart0口接收开始同步字和结束符个数
unsigned char idata uart0_num; //uart0口接收、发送字符个数
unsigned char idata battery_volt; //电池电压 battery_volt=60*(battery_ad÷battery_base)
unsigned char idata battery_base[3]; //电池标称ad值和标称时的电压
unsigned int idata battery_ad; //电池当前ad值
unsigned int idata battery_sampling[4]; //电池采样周期瞬时值
void main(void)
{
//*************************************************************
//******系统初始化*********************************************
/*初始化------------------------------*/
P1MDIN=0xFF;
EMI0CF=0x03;
XBR0=0x04; //00000100B /* UART0*/
// XBR1=0x04; //00000100B /* INT0 */
XBR2=0x42; //01000010B /* 弱上拉允许,允许交叉开关,UART1不连到端口 */
//UART0初始化
TL1=0xfd;
TH1=0xfa; //定时器T1装载值 FDH(9600), FAH(4800), F4H(2400), E8(1200)
SCON0=0x50; //设串口UART0为模式1(用于无线通信或PC通信) (用T1)
//定时器设定
CKCON=0x00; //T0,T1,T2,T4使用SYSCLK的12分频
T2CON=0x04; //T1为UART0串口波特率发生器,启动T2
TMOD=0x21; //T0为定时方式1,T1为8位自动装载为UART0串口波特率发生器
TR1=1; //启动T1
//DAC0设置
P0MDOUT=0x01; //00000001B /*P0配置*/
P1MDOUT=0xff; /*P1*/
P2MDOUT=0xff; /*P2*/
P3MDOUT = 0xff; //11111111B P3口配置 /*各个端口输入时配置为漏极开路,输出时配置为推挽方式*/
P74OUT=0x00;
P4=P4&0xd3; /*ALE=0,A16=0(P4.3),LCDE=0(P4.2)*/
WDTCN=0xde; /*暂时禁止看门狗定时器*/
WDTCN=0xad;
SCON0=SCON0&0xfc; //清TI0,RI0
//外部中断设置
IE0=0; /* 清中断标志 */
ES0=1; //开放串口UART0中断
EA=1; //开总中断
AMX0SL=0x07;
//初始化
P5=P5&0xfd; //开机点亮工作灯
while (1);
}
void uart0_rt(void) interrupt 4
{
k=0;
if (RI0==1)
{
RI0=0;
k=SBUF0;
}
} |