一个按键1 如果按下,就使 N76E003串口0 发送1到串口调试助手,但是老是有问题,哪位大神帮帮我。代码如下: #include "n76e003.h" #include "stdio.h" #define uint32 unsigned int //typedef unsigned int uint32; void delay_us(int n) { int m; for(m=0;m } void delay_ms(int j) { int k; for(k=0;k delay_us(1000); } void P0_P1_Mode(void) { P0M1=0x3A; P0M2=0x3B; //设置P0 P1M1=0xA0; P1M2=0xBF; //设置P1 } sbit s1 = P0^0; sbit s2 = P1^0; sbit s3 = P1^1; sbit s4 = P1^2; sbit s5 = P1^3; sbit s6 = P1^4; void UART0_Init(uint32 Baud) //设置串口0 { P0_P1_Mode(); ES=1; //使能所有中断 ES=1; //串口0中断使能 ET1=0; //关闭定时器1中断 SCON = 0x52; //串口0选择模式1 SM0=0 SM1=1 REN=1 TI=1 T3CON|=0x00; //选择定时器1 BRCK=0 PCON |=0x80; //定时器1的波特率加倍 SMOD=1 CKCON|=0x10; //定时器1的时钟源为系统时钟 T1M=1 TMOD |=0x20; //定时器1选择模式2 8位计数器,数值从TH1自动重装载入TL1 M1=1 M0=0 2^8=256 #ifdef FOSC_160000 TH1 = 256 - (1000000/Baud+1); /*16 MHz */ #endif TCON |=0x40; //定时器1启动 TR1=1 } void Send_Data_UART0(int a) { TI=0; SBUF=a; //串口0数据缓存寄存器 while(TI==0); } int main() { s1=1; s2=1; s3=1; s4=1; s5=1; s6=1; UART0_Init(9600); while(1) { if(s1=0) { Send_Data_UART0(1); } delay_ms(10); if(s2=0) { Send_Data_UART0(2); } delay_ms(10); if(s3=0) { Send_Data_UART0(3); } delay_ms(10); if(s4=0) { Send_Data_UART0(4); } delay_ms(10); if(s5=0) { Send_Data_UART0(5); } delay_ms(10); if(s6=0) { Send_Data_UART0(6); } delay_ms(10); } }
|