|
50黑幣
從網(wǎng)上下載的程序,下載到板子試了,就一直這樣顯示不動,大佬幫忙看下程序問題出在哪
#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[]="藍(lán)色:";
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; // 數(shù)據(jù)口先送 0xff
LCD_RS=0; // 指令
LCD_RW=1; // 讀出忙標(biāo)志(BF)及地址記數(shù)器(AC)
LCD_EN=1; // 使能
while(P0&0x80); // 最高位為1則忙,再讀
LCD_EN=0;
}
void LCD_cmd(char md,char dt) //寫指令或數(shù)據(jù) md=0命令 md=1數(shù)據(jù)
{
LCD_Busy(); // 測試液晶是否忙
if(md) LCD_RS=1; // 判斷是數(shù)據(jù)還是命令
else LCD_RS=0;
LCD_RW=0; // 寫
P0=dt; // 送數(shù)據(jù)或命令
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); // 關(guān)閉圖形顯示 *
delay(100);
LCD_cmd(0,0x30); // 基本指令動作
delay(100);
LCD_cmd(0,0x06); // 光標(biāo)的移動方向
delay(100);
LCD_cmd(0,0x0c); // 開顯示,關(guān)光標(biāo)
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); // 開顯示,關(guān)光標(biāo)
//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; //關(guān)定時器0中斷
ET1=1; // 開定時器0中斷
TR0=0; //關(guān)定時器0
TR1=1; //啟動定時器1
EX0=1; //開外部中斷0
EX1=0; // 關(guān)外部中斷1
IT0=1; //外部中斷0跳變沿觸發(fā)
}
void timer0() interrupt 1
{
counter++;
}
void timer1() interrupt 3
{
TH1=(65536-60000)/256;
TL1=(65536-60000)%256;
EA=0;//關(guān)總中斷
EX0=0;
TR1=0;
flag++;//實現(xiàn)先檢測紅色,再檢測藍(lán)色,然后檢測綠色,循環(huán)檢測
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;//下次檢測藍(lán)色(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,"藍(lán)色");
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;//清零外中斷計數(shù)標(biāo)志
TR0=1;
EX0=1;
TR1=1;
EA=1;
}
void main(void)
{
LCD_init();
INTER_init();
while(1)
{
DisplayScreen();
delay(100);
}
}
|
|