发表于:2014/7/24 15:38:52
#0楼
各位高手,小弟正在基于STC单片机开发程序,在定时器1中断处理程序中,添加LCD显示程序。系统运行后,LCD显示乱码。在主函数中也添加了LCD显示代码,能够正常显示。请教其中的原因。谢谢!
/*****************************定时器1中断子程序*****************/
void time1(void) interrupt 3 using T1_INTNO
{
ET1 = 0;/*关闭定时器1中断*/
/*打印count1和count2*/
qian1=(count1/1000)+48; /*为了便于显示,转换为ASCII码*/
bai1=(count1%1000/100)+48; //百位转换成字符
shi1=(count1%100/10)+48; //十位转换成字符
ge1=(count1%100%10)+48; //个位转换成字符
qian2=(count2/1000)+48;
bai2=(count2%1000/100)+48;
shi2=(count2%100/10)+48;
ge2=(count2%100%10)+48;
LCD_write_char(2,1,qian1);
LCD_write_char(3,1,bai1);
LCD_write_char(4,1,shi1);
LCD_write_char(5,1,ge1);
LCD_write_char(8,1,qian2);
LCD_write_char(9,1,bai2);
LCD_write_char(10,1,shi2);
LCD_write_char(11,1,ge2);
TH1=(65536-10)/256; //重新给定时器赋初值
TL1=(65536-10)%256;
t++; //每中断一次t加1
if(t<=count1) //电机1调速占空比为count1 : 100
{
pwm1=1;
}
else
{
pwm1=0;
}
if(t<=count2) //电机2调速占空比为count2 : 100
{
pwm2=1;
}
else
{
pwm2=0;
}
if(t>=100) //设置总占空比时间为1Kus
{
t=0;
}
TF1 = 0;/*清除中断标志位*/
ET1 = 1;/*打开定时器1中断*/
}
/*****************************定时器1中断子程序*****************/
void time1(void) interrupt 3 using T1_INTNO
{
ET1 = 0;/*关闭定时器1中断*/
/*打印count1和count2*/
qian1=(count1/1000)+48; /*为了便于显示,转换为ASCII码*/
bai1=(count1%1000/100)+48; //百位转换成字符
shi1=(count1%100/10)+48; //十位转换成字符
ge1=(count1%100%10)+48; //个位转换成字符
qian2=(count2/1000)+48;
bai2=(count2%1000/100)+48;
shi2=(count2%100/10)+48;
ge2=(count2%100%10)+48;
LCD_write_char(2,1,qian1);
LCD_write_char(3,1,bai1);
LCD_write_char(4,1,shi1);
LCD_write_char(5,1,ge1);
LCD_write_char(8,1,qian2);
LCD_write_char(9,1,bai2);
LCD_write_char(10,1,shi2);
LCD_write_char(11,1,ge2);
TH1=(65536-10)/256; //重新给定时器赋初值
TL1=(65536-10)%256;
t++; //每中断一次t加1
if(t<=count1) //电机1调速占空比为count1 : 100
{
pwm1=1;
}
else
{
pwm1=0;
}
if(t<=count2) //电机2调速占空比为count2 : 100
{
pwm2=1;
}
else
{
pwm2=0;
}
if(t>=100) //设置总占空比时间为1Kus
{
t=0;
}
TF1 = 0;/*清除中断标志位*/
ET1 = 1;/*打开定时器1中断*/
}
5分悬赏