#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit E=P2^7;
sbit RW=P2^6;
sbit RS=P2^5;
sbit PWM=P1^0;
sbit fz=P1^1;
sbit key=P2^0;
sbit p33=P3^3;
uchar count;
uchar N=0;
uchar count_high,count_low;
void Delay()
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void delay(uint i)
{
uint x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
bit Busy(void)
{
bit busy_flag = 0;
RS = 0;
RW = 1;
E = 1;
Delay();
busy_flag = (bit)(P0 & 0x80);
E = 0;
return busy_flag;
}
void wcmd(uchar del) //
{
while(Busy());
RS = 0;
RW = 0;
E = 0;
Delay();
P0 = del;
Delay();
E = 1;
Delay();
E = 0;
}
void wdata(uchar del)
{
while(Busy());
RS = 1;
RW = 0;
E = 0;
Delay();
P0 = del;
Delay();
E = 1;
Delay();
E = 0;
}
void L1602_init(void)
{
wcmd(0x38);
delay(5);
wcmd(0x38);
delay(5);
wcmd(0x38);
delay(5);
wcmd(0x38);
wcmd(0x08);
wcmd(0x0c);
wcmd(0x04);
wcmd(0x01);
}
void L1602_char(uchar hang,uchar lie,char sign)
{
uchar a;
if(hang == 1) a = 0x80;
if(hang == 2) a = 0xc0;
a = a + lie - 1;
wcmd(a);
wdata(sign);
}
void L1602_string(uchar hang,uchar lie,uchar *p)
{
uchar a,b=0;
if(hang == 1) a = 0x80;
if(hang == 2) a = 0xc0;
a = a + lie - 1;
while(1)
{
wcmd(a++);
if((*p == ' ')||(b==16)) break;
b++;
wdata(*p);
p++;
}
}
void read_count()
{
do
{
count_high=TH1;
count_low=TL1;
}
while(count_high!=TH1);
}
//这里应该要加一个显示变量,然后送给1602实时显示
void main()
{
TMOD=0x91;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TH1=0;
TL1=0;
ET0=1;
TR0=1;
EA=1;
while(1)
{
fz=0;
if(key==0)
{
delay(100);
if(key==0)
{
N=N+1;
if(N>100)
N=0;
}
}
delay(100);
while(p33==0);
TR1=1;
while(p33==0);
while(p33==1);
TR1=0;
read_count;
delay(30);
L1602_init();
L1602_string(1,1,"welcom to");
L1602_string(2,1,"The Mcu World");
L1602_char(1,1,'*');
L1602_char(1,6,'*');
while(1);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
楼主先说明是什么问题,报错提示是什么?还有你的分析。
现在就是仿真图好像不对,另外问一下,在protuse中,通过PWM测速,是不是只能通过L298的en断才可以啊?在一个光耦那里好像不对啊,一直采集不到信号,已经改了好多次了 就是不行
一周热门 更多>