单片机或c语言,哪位高手帮我解释一下谢谢了
单片机或c语言,哪位高手帮我解释一下谢谢了1、软件部分#include"reg51.h"#defineGPIO_LED_SEGP2#defineGPIO_LED_BITP...
单片机或c语言,哪位高手帮我解释一下谢谢了1、软件部分
#include "reg51.h"
#define GPIO_LED_SEG P2
#define GPIO_LED_BIT P0
unsigned char a ,i;
unsigned char LED_seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char LED_bit[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char LED_buf[3]={1,2,3 };
//fosc=11.0592MHz,9600bps
//串口初始化函数9600bps
void Sbuf_Init(void)
{
SCON=0x50; //10位方式
//波特率设置
PCON=0x00; //波特率不倍增
TMOD=(TMOD&0x0f)|0x20;//T1方式2
TH1=0xfd; //T1计数初值
TL1=0xfd;
ES=1;EA=1; //串口中断使能
TR1=1; //启动定时器
}
void delay(unsigned int n)
{
unsigned int i;
for(i=0;i<n;i++)
;
}
void main(void)
{
Sbuf_Init();
while(1)
{
GPIO_LED_BIT=LED_bit[i]; //先送位码
GPIO_LED_SEG=LED_seg[LED_buf[i]]; //后送段码
delay(200); //延时5~10ms
i++;
if(i==3)
i=0;
}
/*
{
//串口接收:查询方式
while(RI==0);
RI=0;
a=SBUF;
//串口发送:查询方式
SBUF=a+1;
while(TI==0);
TI=0;
delay(100);
}*/
}
void UART_ISR(void) interrupt 4
{
if(RI)
{
RI=0;
a=SBUF;
LED_buf[0]=(a%100)%10;
LED_buf[1]=(a%100)/10;
LED_buf[2]=a/100;
SBUF=a+1;
}
if(TI)
{
TI=0;
}
} 展开
#include "reg51.h"
#define GPIO_LED_SEG P2
#define GPIO_LED_BIT P0
unsigned char a ,i;
unsigned char LED_seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char LED_bit[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char LED_buf[3]={1,2,3 };
//fosc=11.0592MHz,9600bps
//串口初始化函数9600bps
void Sbuf_Init(void)
{
SCON=0x50; //10位方式
//波特率设置
PCON=0x00; //波特率不倍增
TMOD=(TMOD&0x0f)|0x20;//T1方式2
TH1=0xfd; //T1计数初值
TL1=0xfd;
ES=1;EA=1; //串口中断使能
TR1=1; //启动定时器
}
void delay(unsigned int n)
{
unsigned int i;
for(i=0;i<n;i++)
;
}
void main(void)
{
Sbuf_Init();
while(1)
{
GPIO_LED_BIT=LED_bit[i]; //先送位码
GPIO_LED_SEG=LED_seg[LED_buf[i]]; //后送段码
delay(200); //延时5~10ms
i++;
if(i==3)
i=0;
}
/*
{
//串口接收:查询方式
while(RI==0);
RI=0;
a=SBUF;
//串口发送:查询方式
SBUF=a+1;
while(TI==0);
TI=0;
delay(100);
}*/
}
void UART_ISR(void) interrupt 4
{
if(RI)
{
RI=0;
a=SBUF;
LED_buf[0]=(a%100)%10;
LED_buf[1]=(a%100)/10;
LED_buf[2]=a/100;
SBUF=a+1;
}
if(TI)
{
TI=0;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询