从网上下载的程序,下载到板子试了,就一直这样显示不动,大佬帮忙看下程序问题出在哪
#include<reg52.h>
#include <string.h>
#define uint unsigned int
#define uchar unsigned char
uchar red=0,blue=0,green=0,flag=0,i=0,j=0;
uchar dat[5]={0,0,0,0,0};
uint counter=0;
sbit TCS_OE=P1^0;
sbit TCS_S0=P1^1;
sbit TCS_S1=P1^2;
sbit TCS_S2=P1^3;
sbit TCS_S3=P1^4;
sbit TCS_OUT=P3^2;
sbit LCD_RS=P2^4;
sbit LCD_RW=P2^5;
sbit LCD_EN=P2^6;
sbit LCD_PSB=P2^1;
sbit LCD_RST=P2^3;
sbit LCD_BK=P2^7;
uchar table0[]="颜色识别:";
uchar table1[]="红色:";
uchar table2[]="蓝色:";
uchar table3[]="绿色:";
void delay(uint m) //延时程序
{
unsigned int i,j;
for(i=0;i<m;i++)
for(j=0;j<10;j++);
}
void LCD_Busy(void)// 测试液晶是否忙
{
P0=0xff; // 数据口先送 0xff
LCD_RS=0; // 指令
LCD_RW=1; // 读出忙标志(BF)及地址记数器(AC)
LCD_EN=1; // 使能
while(P0&0x80); // 最高位为1则忙,再读
LCD_EN=0;
}
void LCD_cmd(char md,char dt) //写指令或数据 md=0命令 md=1数据
{
LCD_Busy(); // 测试液晶是否忙
if(md) LCD_RS=1; // 判断是数据还是命令
else LCD_RS=0;
LCD_RW=0; // 写
P0=dt; // 送数据或命令
delay(20);
LCD_EN=1; // 使能
delay(20);
LCD_EN=0;
}
void LCD_init(void)//液晶显示器初始化
{ LCD_PSB=1;
LCD_RST=0;
delay(10);
LCD_RST=1;
LCD_cmd(0,0x34); // 关闭图形显示 *
delay(100);
LCD_cmd(0,0x30); // 基本指令动作
delay(100);
LCD_cmd(0,0x06); // 光标的移动方向
delay(100);
LCD_cmd(0,0x0c); // 开显示,关光标
delay(100);
LCD_cmd(0,0x01); // 清屏,地址指针指向00H
delay(100);
}
void DisplayZF(uchar m,char *p)
{ LCD_cmd(0,m);
while((*p)!='\0')
{ //显示字符" "
LCD_cmd(1,*p++);
}
}
void DisplayScreen()
{ LCD_cmd(0,0x30); // 基本指令动作
//delay(100);
LCD_cmd(0,0x0c); // 开显示,关光标
//delay(100);
DisplayZF(0x80,table0);
//delay(100);
DisplayZF(0x91,table1);
//delay(100);
DisplayZF(0x89,table2);
//delay(100);
DisplayZF(0x99,table3);
//delay(100);
}
void INTER_init()
{ TCS_S0=1;
TCS_S1=1;
TCS_S2=0;
TCS_S3=0;
TCS_OE=1;
TMOD=0x11;
TH1=(65536-60000)/256;
TL1=(65536-60000)%256;
EA=1;//开总中断
ET0=0; //关定时器0中断
ET1=1; // 开定时器0中断
TR0=0; //关定时器0
TR1=1; //启动定时器1
EX0=1; //开外部中断0
EX1=0; // 关外部中断1
IT0=1; //外部中断0跳变沿触发
}
void timer0() interrupt 1
{
counter++;
}
void timer1() interrupt 3
{
TH1=(65536-60000)/256;
TL1=(65536-60000)%256;
EA=0;//关总中断
EX0=0;
TR1=0;
flag++;//实现先检测红色,再检测蓝色,然后检测绿色,循环检测
if(flag==1)
{
red=counter;
dat[0]=counter/1000+0x30;
counter=counter%1000;
dat[1]=counter/100+0x30;
counter=counter%100;
dat[2]=counter/10+0x30;
counter=counter%10;
dat[3]=counter+0x30;
DisplayZF(0x94,dat);
TCS_S2=0;//下次检测蓝色(S2,S3=0,1)
TCS_S3=1;
}
else if(flag==2)
{
blue=counter;
dat[0]=counter/1000+0x30;
counter=counter%1000;
dat[1]=counter/100+0x30;
counter=counter%100;
dat[2]=counter/10+0x30;
counter=counter%10;
dat[3]=counter+0x30;
DisplayZF(0x8c,dat);
TCS_S2=1;//下次检测绿色(S2,S3=1,1)
TCS_S3=1;
}
else if(flag==3)
{
green=counter;
dat[0]=counter/1000+0x30;
counter=counter%1000;
dat[1]=counter/100+0x30;
counter=counter%100;
dat[2]=counter/10+0x30;
counter=counter%10;
dat[3]=counter+0x30;
DisplayZF(0x9c,dat);
TCS_S2=0;//下次检测红色(S2,S3=0,0)
TCS_S3=0;
}
else if(flag==4)
{
flag=0;
if((red+5)>(blue+green))
DisplayZF(0x85,"蓝色");
else if((blue+8>red)&&(blue+2>green))
DisplayZF(0x85,"红色");
/*else if((green-3<red)&&(green-15>blue))
DisplayZF(0x85,"绿色");*/
else if((red>blue)&&(green>blue))
DisplayZF(0x85,"黄色");
else
DisplayZF(0x85,"绿色");
}
counter = 0;//清零外中断计数标志
TR0=1;
EX0=1;
TR1=1;
EA=1;
}
void main(void)
{
LCD_init();
INTER_init();
while(1)
{
DisplayScreen();
delay(100);
}
}
|