发布网友 发布时间:2022-10-12 18:19
共2个回答
热心网友 时间:2023-10-23 19:05
这个是主函数的
1602.h的内容如下:
#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit E=P2^7;
sbit RW=P2^6;
sbit RS=P2^5;
void delay()
{
uchar i=12;
while(i--)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
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);
wcmd(0x0c);
wcmd(0x06);
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++);
b++;
if((*p == '\0')||(b==17)) break;
wdata(*p);
p++;
}
}
热心网友 时间:2023-10-23 19:05
恩,建议你先从一些简单的程序入手,,流水灯数码管什么的,。再去做超声波的设计吧追问这些东西都学过了,现在要做点实用的东西