本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
各位大虾们,帮帮忙!小弟用STC芯片写了一个LCD显示,但不知哪里出现错误,LCD显示却事与愿违!各位能否指教一二,谢谢!
#include< STC_NEW_8051.h >
#define uchar unsigned char
#define uint unsigned int
sbit com1=P3^2;
sbit com2=P3^3;
sbit com3=P3^4;
sbit seg1=P3^5;
sbit seg2=P3^7;
sbit seg3=P1^7;
sbit seg4=P1^6;
sbit seg5=P1^5;
sbit seg6=P1^4;
sbit seg7=P3^0;
sbit seg8=P3^1;
uchar table1[]={0x02,0x9e,0x24,0x0c,0x98,0x48,0x40,0x1e,0x00,0x08};
uchar table2[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};
uchar table3[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
uchar table4[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar m,n,w;
void delay(uint ms)
{
uint i,j;
for(i=ms;i>0;i--)
for(j=880;j>0;j--);
}
void display()
{
uchar x;
if(com1==1)
{
x=table1[m]&0x80;
seg1=x>>7;
x=table1[m]&0x40;
seg2=x>>6;
x=table1[m]&0x20;
seg3=x>>5;
x=table1[m]&0x10;
seg4=x>>4;
x=table1[m]&0x08;
seg5=x>>3;
x=table1[m]&0x04;
seg6=x>>2;
x=table1[m]&0x02;
seg7=x>>1;
}
if(com1==0)
{
x=table2[m]&0x80;
seg1=x>>7;
x=table2[m]&0x40;
seg2=x>>6;
x=table2[m]&0x20;
seg3=x>>5;
x=table2[m]&0x10;
seg4=x>>4;
x=table2[m]&0x08;
seg5=x>>3;
x=table2[m]&0x04;
seg6=x>>2;
x=table2[m]&0x02;
seg7=x>>1;
}
if(com2==1)
{
x=table1[n]&0x80;
seg1=x>>7;
x=table1[n]&0x40;
seg2=x>>6;
x=table1[n]&0x20;
seg3=x>>5;
x=table1[n]&0x10;
seg4=x>>4;
x=table1[n]&0x08;
seg5=x>>3;
x=table1[n]&0x04;
seg6=x>>2;
x=table1[n]&0x02;
seg7=x>>1;
}
if(com2==0)
{
x=table2[n]&0x80;
seg1=x>>7;
x=table2[n]&0x40;
seg2=x>>6;
x=table2[n]&0x20;
seg3=x>>5;
x=table2[n]&0x10;
seg4=x>>4;
x=table2[n]&0x08;
seg5=x>>3;
x=table2[n]&0x04;
seg6=x>>2;
x=table2[n]&0x02;
seg7=x>>1;
}
if(com3==1)
{
x=table3[w]&0x80;
seg1=x>>7;
x=table3[w]&0x40;
seg2=x>>6;
x=table3[w]&0x20;
seg3=x>>5;
x=table3[w]&0x10;
seg4=x>>4;
x=table3[w]&0x08;
seg5=x>>3;
x=table3[w]&0x04;
seg6=x>>2;
x=table3[w]&0x02;
seg7=x>>1;
x=table3[w]&0x01;
seg8=x;
}
if(com3==0)
{
x=table4[w]&0x80;
seg1=x>>7;
x=table4[w]&0x40;
seg2=x>>6;
x=table4[w]&0x20;
seg3=x>>5;
x=table4[w]&0x10;
seg4=x>>4;
x=table4[w]&0x08;
seg5=x>>3;
x=table4[w]&0x04;
seg6=x>>2;
x=table4[w]&0x02;
seg7=x>>1;
x=table4[w]&0x01;
seg8=x;
}
}
void t0() interrupt 1
{
uchar num;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
num++;
if(num==1)
{
P3M1=0X1a; //0001 1010
P3M0=0X04; //0000 0100
com1=1;
}
if(num==2)
{
com1=0;
}
if(num==3)
{
P3M1=0X16; //0001 0110
P3M0=0X08; //0000 1000
com2=1;
}
if(num==4)
{
com2=0;
}
if(num==5)
{
P3M1=0X0e; //0000 1110
P3M0=0X80; //0001 0000
com3=1;
}
if(num==6)
{
com3=0;
num=0;
}
display();
}
void init()
{
EA=1;
ET0=1;
TR0=1;
TMOD=0X01; TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
m=n=w=0;
P3M1=0X1e;
P3M0=0X00;
delay(10);
}
void main()
{
init();
while(1)
{
display();
}
} |