#include <STC15.H>
#include <intrins.h>
#include <iic.h>
#include <stdlib.h>
//#include <IAP.h>
sbit INT0 = 0xB2;
typedef unsigned char u8;
typedef unsigned int u16;
u8 First_Int = 0;
#define Buf2_Max 64
xdata u8 buffer[Buf2_Max];
u8 setwendu;
sbit bb=P3^2;
sbit aa=P1^0;
void UartInit(void) //9600bps@11.0592MHz
{
//P_SW1=0x40; //修改串口1至P3.6 P3.7.
SCON = 0x50; //8位数据,可变波特率
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
T2L = 0xE0; //设定定时初值
T2H = 0xFE; //设定定时初值
AUXR |= 0x10; //启动定时器2
ES = 1; //串口中断打开
EA = 1; //总中断允许
}
void Uart() interrupt 4 using 2
{
ES=0; //
if (RI)
{
RI=0; //
buffer[First_Int] = SBUF; //
First_Int++; //
if(First_Int > Buf2_Max) //
{
First_Int = 0;
}
}
if (TI)
{
TI=0; //
}
ES=1; //
}
void UART1_SendData(u8 dat) //发送8位,一个字节数
{
ES=0;
SBUF=dat; //sfr SBUF = 0x99;
while(TI!=1);
TI=0; //sbit TI = SCON^1; sfr SCON = 0x98;
ES=1;
}
void Delay1000ms() //@11.0592MHz 延时1s发送
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 43;
j = 6;
k = 203;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void exint0() interrupt 0 //判断旋钮方向
{
unsigned char i0, j0;
EX0 = 0;
_nop_();
_nop_();
_nop_();
i0 = 11;
j0 = 190;
do
{
while (--j0);
} while (--i0);
if(aa!=bb)
{
setwendu++;
}
if(aa==bb)
{setwendu--;}
EX0 = 1;
}
void main()
{
u8 fff =0x00;
u8 ii = 0x00;
setwendu = 0x64;
INT0 = 1;
IT0 = 0;
EX0 = 1;
UartInit();
while(1)
{
readth();
for(ii=0;ii<12;ii++)
{
fff=result[ii];
UART1_SendData(fff);
}
Delay1000ms();
//UART1_SendData(setwendu);
}
}
评论2