写了个简单的164驱动6位数码管、串口通讯测试程序:164驱动6位数码管,定时器间隔1秒,自动向串口发送数据,共17位数据
问题是:每当向串口发送数据时,数码管都会闪烁一下,不发送数据时,数码管显示正常。以下是程序,帮忙看看哪里有问题?谢谢
#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void) //10ms
{
TCNT0 = 0x94;
timer0_1s_temp++;
if(timer0_1s_temp>=100)
{
timer0_1s_temp=0;
uart_receive_ok=1;
}
}
void send_byte1_164(unsigned char byte)
{
unsigned char num,c;
if((byte&0x80)==0x80)
{
num=table1[byte&0x7F]|0x80;
}
else
{
num=table1[byte&0x7F];
}
for(c=0;c<8;c++)
{
if(( num & 0x80)) //(0x80即十进制的128, 二进制的10000000 按位发送)
{
ab_set;
}
else
{
ab_clr;
}
NOP();NOP();NOP();
cp_set;
NOP();NOP();NOP();
cp_clr;
num= num<<1;
}
}
void dis_led(void)
{
send_byte1_164(1);
led_1_set;
delayms(1);
led_1_clr;
send_byte1_164(2);
led_2_set;
delayms(1);
led_2_clr;
send_byte1_164(3); // "-"
led_3_set;
delayms(1);
led_3_clr;
send_byte1_164(4);
led_4_set;
delayms(1);
led_4_clr;
send_byte1_164(5);
led_5_set;
delayms(1);
led_5_clr;
send_byte1_164(6);
led_6_set;
delayms(1);
led_6_clr;
}
void main(void)
{
CLI();
port_init();
timer0_init();
usart_init(); //串口初始化
MCUCR=0x00;
GICR=0x00;
TIMSK=0x01;
SEI();
while(1)
{
dis_led();
if(uart_receive_ok) //串口发送数据
{
uart_receive_ok=0;
xor_check=0;
for(send_temp=0;send_temp<16;send_temp++)
{
usart_send_data(send_buf[send_temp]);
xor_check^=send_buf[send_temp]; //异或校验
}
usart_send_data(xor_check); //发送异或校验码
timer0_1s_temp=0;
}
}
}
|