关于单片机液晶1602的程序片段问题 51单片机+LCD1602显示字符程序问题

作者&投稿:巴店 (若有异议请与网页底部的电邮联系)
应该不是判断忙碌或者不只是判断忙碌,这个语句应该是送了一串命令进去
//HD44780 LCD DRIVER

#include <AT89X52.H>
#include <ctype.h>

//LCD Commands
#define LCD_CLS 1 //Clears entire display and sets DDRAM address 0
#define LCD_HOME 2 //Sets DDRAM address 0 in address counter.
#define LCD_SETMODE 4 //Sets cursor move direction and specifies display shift.
#define LCD_SETVISIBLE 8 //Sets entire display (D) on/off,cursor on/off (C), and blinking of cursor position character (B).
#define LCD_SHIFT 16 //Moves cursor and shifts display without changing DDRAM contents.
#define LCD_SETFUNCTION 32 //Sets interface data length (DL), number of display lines (N), and character font (F).
#define LCD_SETCGADDR 64 //Sets CGRAM address.CGRAM data is sent and received after this setting.
#define LCD_SETDDADDR 128 //Sets DDRAM address. DDRAM data is sent and received after this setting.

#define TURE 1
#define FORSE 0
#define TMH 0xf8 //delay timeh 2ms
#define TML 0xCD //delay timel
//------------------------------------------
#define MAX_DISPLAY_CHAR 2
//-----------------------------------------

unsigned char code text[6]="hellow";
static unsigned char data counter,a;

void wcchar(unsigned char d); //write a command char
void wdchar(unsigned char i); //write a data char
char wtbusy(); //wait busy sign
void clrscr(void); //clear screen
void initime0(void); //initial time0
void delay(unsigned char i); //delay

//-------------------------------
unsigned char crc8(unsigned char *pData,unsigned char count);
unsigned char pData[]={0x33,0x12,0x34,0x56,0x78,0x33,0x12,0x23,0x45,0x56};
unsigned char data crc;
static char outputbuffer[MAX_DISPLAY_CHAR];
char *calc_decascii(char num);
//-------------------------------

void ISR_Timer0(void) interrupt 1
{
TL0=TML;
TH0=TMH;
counter--;
}

void ISR_Int0(void) interrupt 0
{

wdchar(text[a++]); //display "hellow"
if (a>=6)
{a=0;wdchar(' ');}
}

//main program display "hellow"

main(void)
{
unsigned char data k;
initime0();
wcchar(0x38); //initial lcd
wcchar(LCD_SETVISIBLE+6); //set lcd visible
clrscr(); //clear lcd

while(1)
{
crc8(&pData,10);
calc_decascii(crc);
wdchar (outputbuffer[1]);
wdchar (outputbuffer[2]);
wdchar (' ');

for(k=0;k<=6;k++)
{
// wdchar(text[k]); //display "hellow"
P1_2=0;
delay(55); //delay
P1_2=1;
delay(55); //delay
}
}
}

//sub function || display a char
void wdchar(unsigned char i) //write a char
{
unsigned char xdata *j;
P1_0=1;
P1_1=0;
j=0x8000;
*j=i;
while (wtbusy())
{}

}

void wcchar(unsigned char d) //write a command char
{
unsigned char xdata *j;
P1_0=0;
P1_1=0;
j=0x8000;
*j=d;
while (wtbusy())
{}
}

char wtbusy() //wait busy sign
{
unsigned char xdata *j;
P1_0=0;
P1_1=1;
j=0x8000;
if(*j&0x80)
{
return TURE;
}
else
{
return FORSE;
}
}

//clear screen
void clrscr()
{
wcchar(LCD_CLS);
}

//initial time0
void initime0()
{
TL0=TML;
TH0=TMH;
TR0=TURE;
IE=0x93; //Enable T0 and Serial Port.
}

//sub function time delay
void delay(unsigned char i)
{
counter=i;
while (counter)
{}
}

unsigned char crc8(unsigned char *pData,unsigned char count)

{
// unsigned char crc;
crc = 0;

while (count-- > 0)

{
crc ^= *pData++;
}
return crc;

}

char *calc_decascii(char num)
// A rather messy function to convert a floating
// point number into an ASCII string.
{ long data temp = num;
char data *arrayptr = &outputbuffer[MAX_DISPLAY_CHAR];
long data divisor = 10;
long data result;
char data remainder,asciival;
int data i;

// If the result of the calculation is zero
// insert a zero in the buffer and finish.
if (!temp)
{ *arrayptr = 48;
goto done;
}
// Handle Negative Numbers.
if (temp < 0)
{ outputbuffer[0] = '-';
temp -= 2*temp;
}

for (i=0 ; i < sizeof(outputbuffer) ; i++)
{ remainder = temp % divisor;
result = temp / divisor;

// If we run off the end of the number insert a space into
// the buffer.
if ((!remainder) && (!result))
{ *arrayptr = ' ';}

// We're in business - store the digit offsetting
// by 48 decimal to account for the ascii value.
else
{ asciival = remainder + 48;
*arrayptr = asciival;
}

temp /= 10;
// Save a place for a negative sign.
if (arrayptr != &outputbuffer[1]) arrayptr--;
}
done: return outputbuffer;
}

dat = ((dat&0x01)<<7)|((dat&0x02)<<5)|((dat&0x04)<<3)|((dat&0x08)<<1)|((dat&0x10)>>1)|((dat&0x20)>>3)|((dat&0x40)>>5)|((dat&0x80)>>7);
这一句,不是检测忙的。
这一句,是把dat中的:
第7位和第0位交换、第6位和第1位交换、第5位和第2位交换、第4位和第3位交换。

如果你不想加那一句,可以把busy的标志位改一下,如下也行
bit bz()
{
bit result;
RS=0;
RW=1;
EN=1;
_nop_();
_nop_();
_nop_();
_nop_();
result=(bit)(P0&0x01);
EN=0;
return result;
}

单片机液晶屏LCD1602的问题,这程序如何实现倒数功能啊?~

用个定时器,定时器里面对这个数(假设这个数为shu)进行shu--,减到0的话就给shu=100进行赋值
然后主程序里面就直接去显示就好了
void timer0(void) interrupt 1
{
TH0=0xXX;

TL0=0xXX;

if(shu==0)

shu=100;
else
shu--;
}

感觉这代码有点乱

试一下我的吧
#include

#ifndef unsi8
#define unsi8 unsigned char
#endif

#ifndef unsi_16
#define unsi_16 unsigned short
#endif

#define OUT P0
#define DELAY

sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_E_ = P2^2;

#define LCD_WR_CMD 0
#define LCD_WR_DATA 1

struct Passer
{
unsi8 String[12];
unsi8 String2[11];
};
struct Passer Disp={
'7','4','2','6','1','5','0','5','5','0','2','5',
'H','e','l','l','o',',','W','o','r','l','d'
};

#ifdef DELAY
void Delay_1ms(unsi_16 x)
{
unsi8 i;
while(x--)
{
for(i=0;i<125;i++);
}
}
#endif

static void LCD_Busy()
{
unsi8 i;
do
{
LCD_RS = 0;
LCD_RW = 1;
LCD_E_ = 1;
i = OUT;
LCD_E_ = 0;
}while(i&0x80);
}

static void LCD_WriteByte(unsi8 Dat,bit Mode)
{
unsi8 i;
LCD_Busy();
LCD_RS = Mode;
LCD_RW = 0;
OUT = Dat;
LCD_E_ = 1;
for(i=0;i<251;i++);
LCD_E_ = 0;
}

static void LCD_Set_Register()
{
LCD_WriteByte(0x38,LCD_WR_CMD);
LCD_WriteByte(0x01,LCD_WR_CMD);
LCD_WriteByte(0x06,LCD_WR_CMD);
LCD_WriteByte(0x0f,LCD_WR_CMD);
}

void Display()
{

unsi8 i;
LCD_WriteByte(0x82,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String);i++)
{
LCD_WriteByte(Disp.String[i],LCD_WR_DATA);
Delay_1ms(300);
}
LCD_WriteByte(0xc2,LCD_WR_CMD);
for(i=0;i<sizeof(Disp.String2);i++)
{
LCD_WriteByte(Disp.String2[i],LCD_WR_DATA);
Delay_1ms(300);
}
}

void main()
{

while(1)
{
LCD_Set_Register();
Display();
}
}

如有问题可再咨询

能帮我编一个用1602液晶显示摄氏度的程序吗?很感谢
答:{ lcd_init();wr_com(0x80);display(str1);wr_com(0xc0);display(str2);} /***ds1820程序***/ void delay_18B20(unsigned int i)//延时1微秒 { while(i--);} void ds1820rst()/*ds1820复位*/ { unsigned char x=0;DQ = 1; //DQ复位 delay_18B20(4); //延时 DQ =...

51单片机液晶1602的C程序谁有,给个简单的显示一个字符A的
答:include "reg52.h"sbit LED=P1^0;//LED锁存器 sbit SEG=P1^1;//数码管段选锁存器 sbit DIG=P1^2;//数码管位选锁存器 unsigned char t;sbit LCDRS=P2^7;//数据指令控制 sbit LCDRW=P2^6;//读写控制 sbit LCDEN=P2^5;//液晶屏使能控制 //***延时函数,延时n*1ms void delay(...

...一个c语言程序 用at89c52单片机要求使用1602液晶显示当前时间和温度...
答:/*--- 名称:18B20温度传感器 网站:www.doflye.net 编写:shifang 日期:2009.5 修改:无 内容:18B20单线温度检测的应用样例程序---*//*--- 18b20初始化---

基于AT89C51单片机和DS18B20温度传感器、LCD1602液晶显示的高精度数字温...
答:/***ds18b20子程序***/ /***ds18b20延迟子函数(晶振12MHz )***/ include<reg51.h> sbit DQ=P1^2;define uchar unsigned char void delay_18B20(unsigned int i){ while(i--);} /***ds18b20初始化函数***/ void Init_DS18B20(void){ unsigned char x=0;DQ = 1; //DQ复位 del...

要求在1602lcd的第一行中间显示一位数加法及结果:2十3=5的单片机...
答:FYI include <reg52.h>#include <intrins.h>typedef unsigned char u8; // 重命名类型u8简化代码编写typedef unsigned int u16;#define LCD1602_DATA_PORT P0// LCD1602的8位数据端口sbit gLcd1602_E = P2^7;// LCD1602控制总线的使能信号sbit gLcd1602_RW = P2^5;// LCD1602控制总线的读写...

单片机液晶显示驱动程序(用C语言写的)
答:1602A液晶屏驱动程序** 晶 振 频 率:11.0592M***/#include <reg51.h>#define uchar unsigned char#define uint unsigned int sbit LCM_E=P3^5;//定义接口sbit LCM_RW=P3^6;sbit LCM_RS=P3^7; #define LCM_Data P1//数据接口 void LCM_WriteData(uchar WDLCM);void LCM_WriteCommand...

单片机1602液晶怎样移屏?怎样设置光标闪烁?谁有没有这样的C程序?
答:void write_wei(uchar wei, uchar shu ) //一个显示时间,一个现实在液晶屏那个位置 { uchar shi,ge;shi=shu/10; //显示两位数的高位 ge=shu%10;// 显示两位数的高低 write_e(0x80+0x40+wei);write_f(0x30+shi);write_f(0x30+ge);} void init (){ EN=0;//使能端 miao=...

用1602 液晶显示器实现一段文字的动态显示;显示过程由按键通过单片机控 ...
答:;END DELAY1:MOV R5,#05H D2: MOV R7,#38H D1: MOV R6,#0F9H DJNZ R6,DJNZ R7,D1 DJNZ R5,D2 RET END 把END放到最后试试。因为程序已经结束了,你又弄出个DELAY1这子程序出来,编译时,当然不认识了。另外,虚机团上产品团购,超级便宜 ...

单片机与DS18B20并用LCD1602显示 c程序
答:单片机与DS18B20并用LCD1602显示 c程序 这是电路的连接sbitDQ=P1^4;//ds18b20与单片机连接口sbitRS=P1^3;sbitRW=P1^2;sbitEN=P1^1;还有我的LCD的16引脚接到了单片机上的P1.0上,就是要用软件使LCD亮,硬件已经做出来了,所以... 这是电路的连接sbit DQ=P1^4;//ds18b20与单片机连接口sbit RS=P1^3;sbit...

单片机键盘及1602显示程序
答:我有 at89s52 的键盘 和1602初始化程序,你可以组装一下,STC12C5A08AD单片机和at89s52 差不多。include<at89x52.h> include<intrins.h> sbit d_i=P1^0;sbit r_w=P1^1;sbit e=P1^2;define uchar unsigned char define nop _nop_()void delay(unsigned int ttt) // 长延时,ttt为...