标题:
请大神看看这个TM1621B的单片机驱动程序哪里不对
[打印本页]
作者:
PDDDF
时间:
2020-3-9 12:19
标题:
请大神看看这个TM1621B的单片机驱动程序哪里不对
#include <STC15W408AS.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define BIAS 0x52 //0x29
#define SYSEN 0x02 //0x01
#define SYSDIS 0x00
#define LCD_ON 0x06 //0x03
#define LCD_OFF 0x04 //0x02
sbit DATA = P3^3;
sbit WR = P3^4;
sbit CS = P2^3;
uchar time,c;
void send_Hbit_data(uchar dat,uchar cnt)
{
uchar i;
for (i = 0;i<cnt;i++)
{
if(dat & 0x80) {DATA = 1;}
else {DATA = 0;}
_nop_();
WR = 0;
_nop_();
WR = 1;
dat<<=1;
}
WR = 0;
DATA = 0;
}
void send_Lbit_data(uchar dat,uchar cnt)
{
uchar i;
for(i = 0;i<cnt;i++)
{
if(dat & 0x01) {DATA = 1;}
else {DATA = 0;}
_nop_();
WR = 0;
_nop_();
WR = 1;
dat>>=1;
}
WR = 0;
DATA = 0;
}
void command(uchar cmd)
{
CS = 0;
send_Hbit_data(0x80,4);
send_Hbit_data(cmd,8);
CS = 1;
}
void display(uchar add,uchar dat)
{
CS = 0;
send_Hbit_data(0xa0,3);
send_Hbit_data(add<<2,6);
send_Lbit_data(dat,4);
CS = 1;
}
void initT0()//20ms
{
TMOD = 0x00;
TH0 = 0xb1;
TL0 = 0xdf;
EA = 1;
ET0 = 1;
TR0 = 1;
PT0 = 1;
}
void T0int() interrupt 1
{
time++;
if(time == 50) {time = 0;c++;}
}
void delay(uchar a)
{
uchar b;
b = 200;
while(a--)
{
while(b--);
}
}
void main()
{
initT0();
delay(1);
while(1)
{
if(c == 5)
{
command(BIAS); //A
command(SYSEN); //B
command(LCD_ON); //C
display(0x09,0x0f);
while(1);
}
}
}
复制代码
ABC三条命令发送完后,整个液晶屏所有的灯都亮了,后面那个display函数功能无法体现,求教
作者:
zhanghyg
时间:
2020-3-9 15:01
程序死在最后那个 while(1);上了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1