标题:
stc12c5a60s2单片机12m晶振1602显示程序问题
[打印本页]
作者:
maizhi99
时间:
2019-7-9 08:20
标题:
stc12c5a60s2单片机12m晶振1602显示程序问题
#include <STC12C5A60S2.H>
#include <intrins.h>
sbit RS=P4^3;
sbit RW=P4^4;
sbit E=P4^5;
/*********************************************************************************************
函数名:毫秒级CPU延时函数
调 用:DELAY_MS (?);
参 数:1~65535(参数不可为0)
返回值:无
结 果:占用CPU方式延时与参数数值相同的毫秒时间
备 注:应用于1T单片机时i<600,应用于12T单片机时i<125
/*********************************************************************************************/
void Delay1602 (unsigned int a){
unsigned int i;
while( a-- != 0){
for(i = 0; i < 600; i++);
}
}
/*********************************************************************************************/
//写数据函数
void LCD1602_Write_data(unsigned char databuf)
{
RS=1;
RW=0;
P0=databuf;
E=1;
E=0;
}
//写指令函数
void LCD1602_Write_com(unsigned char combuf)
{
RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
//忙检测函数
void Lcd1602_busy(void)
{
RS=0;
RW=1;
P0=0xFF;
E=1;
while(P0^7==1);
E=0;
}
//写指令函数带忙检测
void LCD1602_Write_com_busy(unsigned char combuf)
{
Lcd1602_busy();
RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
//写数据带忙检测函数
void LCD1602_Write_data_busy(unsigned char databuf)
{
Lcd1602_busy();
RS=1;
RW=0;
P0=databuf;
E=1;
E=0;
}
//初始化 l
void Lcd1602_init(void)
{
Delay1602(15);
LCD1602_Write_com(0x38);
Delay1602(5);
LCD1602_Write_com(0x38);
Delay1602(5);
LCD1602_Write_com(0x38);
LCD1602_Write_com_busy(0x38);
LCD1602_Write_com_busy(0x08);
LCD1602_Write_com_busy(0x01);
LCD1602_Write_com_busy(0x06);
LCD1602_Write_com_busy(0x0c);
}
//写地址函数
void lcd1602_Write_address(unsigned char x,unsigned char y)
{
if(y==0)
LCD1602_Write_com_busy(0x80+x);
else
LCD1602_Write_com_busy(0xc0+x);
}
//显示函数
void Lcd1602_Disp(unsigned char x,unsigned char y,unsigned char buf)
{
lcd1602_Write_address(x,y);
LCD1602_Write_data_busy(buf);
}
void main(void)
{
Lcd1602_init();
Lcd1602_Disp(0,1,'1');
Lcd1602_Disp(1,1,'2');
while(1)
{
}
}
复制代码
各位看看错在哪里呢?1602没有反应
作者:
shannenhuan
时间:
2019-7-9 09:48
用示波器对下波形吧
作者:
鹏博士PBs
时间:
2019-7-9 10:44
示波器和逻辑分析仪检测一下对应波形
作者:
maizhi99
时间:
2019-7-9 12:24
鹏博士PBs 发表于 2019-7-9 10:44
示波器和逻辑分析仪检测一下对应波形
没有示波器啊
作者:
周涛1331
时间:
2019-7-25 10:23
#include <STC12C5A60S2.H>
#include <intrins.h>
sbit RS=P4^3;
sbit RW=P4^4;
sbit E=P4^5;
/*********************************************************************************************
函数名:毫秒级CPU延时函数
调 用:DELAY_MS (?);
参 数:1~65535(参数不可为0)
返回值:无
结 果:占用CPU方式延时与参数数值相同的毫秒时间
备 注:应用于1T单片机时i<600,应用于12T单片机时i<125
/*********************************************************************************************/
void Delay1602 (unsigned int a){
unsigned int i;
while( a-- != 0){
for(i = 0; i < 600; i++);
}
}
/*********************************************************************************************/
//写数据函数
void LCD1602_Write_data(unsigned char databuf)
{
RS=1;
RW=0;
P0=databuf;
E=1;
E=0;
}
//写指令函数
void LCD1602_Write_com(unsigned char combuf)
{
RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
//忙检测函数
void Lcd1602_busy(void)
{
RS=0;
RW=1;
P0=0xFF; // 这个地方出现了问题,P0=0x00;
E=1;
while(P0^7==1); //P0^7==0;
E=0;
}
//写指令函数带忙检测
void LCD1602_Write_com_busy(unsigned char combuf)
{
Lcd1602_busy();
RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
//写数据带忙检测函数
void LCD1602_Write_data_busy(unsigned char databuf)
{
Lcd1602_busy();
RS=1;
RW=0;
P0=databuf;
E=1;
E=0;
}
//初始化 l
void Lcd1602_init(void)
{
Delay1602(15);
LCD1602_Write_com(0x38);
Delay1602(5);
LCD1602_Write_com(0x38);
Delay1602(5);
LCD1602_Write_com(0x38);
LCD1602_Write_com_busy(0x38);
LCD1602_Write_com_busy(0x08);
LCD1602_Write_com_busy(0x01);
LCD1602_Write_com_busy(0x06);
LCD1602_Write_com_busy(0x0c);
}
//写地址函数
void lcd1602_Write_address(unsigned char x,unsigned char y)
{
if(y==0)
LCD1602_Write_com_busy(0x80+x);
else
LCD1602_Write_com_busy(0xc0+x);
}
//显示函数
void Lcd1602_Disp(unsigned char x,unsigned char y,unsigned char buf)
{
lcd1602_Write_address(x,y);
LCD1602_Write_data_busy(buf);
}
void main(void)
{
Lcd1602_init();
Lcd1602_Disp(0,1,'1');
Lcd1602_Disp(1,1,'2');
while(1)
{
}
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1