❶ 單片機1602液晶怎樣移屏怎樣設置游標閃爍誰有沒有這樣的C程序
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar data a[ ]="xian zai shi ";
sbit key0= P2^0;//功能鍵,對位進行選擇
sbit key1=P2^1;// 加位
sbit key2= P2^2;// 減位
sbit EN= P3^4; //讀寫段
sbit RS= P3^5; //使能端
uchar miao,fen,shi;
uchar gongleng;//功能鍵中間變數
uchar g,key0sum;
void xunhuan (uint x)
{
int y,z;
for (y=x;y>0;y--)
for (z=120;z>0;z--);
}
void write_e(uchar e ) //寫密命
{
RS=0;
P1=e;
xunhuan(5);
EN=1;//給使能端一個高脈沖, 因為上升源完成指令
xunhuan(5);
EN=0; //晶元停止工作
}
void write_f(uchar f) //寫操作
{
RS=1;
P1=f;
xunhuan(5);
EN=1;
xunhuan(5);
EN=0;
}
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=0;
fen=0;
shi=0;
write_e(0x38);
write_e(0x0c);
write_e(0x06);
write_e(0x01);
//write_e(0x80+0x40);
for (g=0;g<16;g++) //顯示現在時間
{
write_f(a[g]);
xunhuan(10);
}
write_e(0x80+0x40+6 ); //將要顯示的位置
write_f(':');
xunhuan(5);
write_wei(4,shi);// 時的位置
write_e(0x80+0x40+9 );//將要顯示的位置
write_f(':');
xunhuan(5);
write_wei(7,fen);//分的位置
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void keysan() //按鍵功能端
{
if(key0==0) //判斷功能鍵的按下
{
xunhuan(20);
if(key0==0)
{
(key0sum)++;
while(!key0) ;
if(key0sum==1)
{
TR0=0 ;//關閉定時器終段位
write_e(0x80+0x40+10 );//移動到秒
write_e(0x0f);//游標閃爍,
}
if(key0sum==2)
{
TR0=0 ;//關閉定時器終段位
write_e(0x80+0x40+7 );//移動到分
write_e(0x0f);//游標閃爍,
}
if(key0sum==3)
{
TR0=0 ;//關閉定時器終段位
write_e(0x80+0x40+4 );//移動到時
write_e(0x0f);//游標閃爍,
}
if(key0sum==4)
{
TR0=1 ;//關閉定時器終段位
key0=0 ;//移動到秒
write_e(0x0c);//取消游標閃爍,
}
}
}
/**************/
if (key0!=0 )//判斷功能鍵是否按下去
{
if(key1==0)
{
xunhuan(20);
if(key1==0) //按鍵的加位
{
while(!key1);
/*********************///秒
if(key0sum==1) //若功能鍵按下時一次,說明 游標移到秒
{
miao++;
if(miao==60)
miao=0;
write_wei(10,miao);// 將位和數送到秒
write_e(0x80+0x40+10);
}
/***************************/ //分
if(key0sum==2) //若功能鍵按下時一次,說明移到分
{
fen++;
if(fen==60)
fen=0;
write_wei(7,fen);// 將位和數送到fen
write_e(0x80+0x40+7);
}
/****************/ //時
if(key0sum==3) //若功能鍵按下時一次,說明移到分
{
shi++;
if(shi==60)
shi=0;
write_wei(4,shi);// 將位和數送到fen
write_e(0x80+0x40+4);
}
}
}
}
}
void main()
{
uint m;
init();
write_e(0x80);
for(m=0;m<16;m++)
{
write_f(a[m]);
xunhuan(5);
}
while(1)
{
keysan();
}
}
void T0_timer () interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
g++;
if(g==20)
{
g=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_wei(4,shi);
}
write_wei(7,fen);
}
write_wei(10,miao);
}
}
❷ 關於單片機LCD1602顯示內容左右移動的問題
因為涉及到具體的設計問題,我估計很難有人替你指出問題所在,除非有人和你做過一樣的設計、犯過一樣的錯誤。只能給你兩點建議了:1,仔細閱讀DATASHEET;2,仔細審視你的代碼。是不是感覺說和沒說一個樣?呵呵。其實分析問題的心態很重要,鎮定~~鎮定~~~。
❸ 關於單片機液晶1602的程序片段問題
應該不是判斷忙碌或者不只是判斷忙碌,這個語句應該是送了一串命令進去
//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;
}
❹ 51單片機1602液晶如何讓一行移動 一行不動
直接寫數據到1602里,數據按照移動方式改變,例如第一次寫「abcd」第二次寫「 abcd」
❺ 有關單片機1602液晶顯示漢字並且右移的題目,急急急!!!!
這個問題並不難,如果你對單片機有點了解的話,看一下1602的說明書就會明白。
下面我給你一個參考程序
#include<reg52.h>
#include<intrins.h>
#defineucharunsignedchar
#defineuintunsignedint
sbitE=P2^7;//1602使能引腳
sbitRW=P2^6;//1602讀寫引腳,讀為高,寫位低
sbitRS=P2^5;//1602數據命令選擇引腳,數據為高,指令為低
ucharnum;
//延時函數,延時del*1ms
voiddelay(intdel)
{
intx,y;
for(x=0;x<del;x++)
for(y=0;y<110;y++);
}
//寫命令
voidwrite_com(ucharcom)
{
P0=com;
RS=0;
RW=0;
E=0;
delay(5);
E=1;
delay(5);
}
//寫數據
voidwrite_data(uchardate)
{
P0=date;
RS=1;
RW=0;
E=0;
delay(5);
E=1;
delay(5);
}
/*********************
1602初始化函數
*********************/
voidinit()
{
write_com(0x01);
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x80);
}
/********************************************************************
*名稱:L1602_string(ucharhang,ucharlie,uchar*p)
*功能:改變液晶中某位的值,如果要讓第一行,第五個字元開始顯示"abcdef",調用該函數如下
L1602_string(1,5,"abcdef;")
*輸入:行,列,需要輸入1602的數據
*輸出:無
***********************************************************************/
voidwrite_string(ucharhang,ucharlie,uchar*p)
{
uchara;
if(hang==1)a=0x80+0x10;
if(hang==2)a=0xc0+0x10;
a=a+lie-1;
write_com(a);
while(1)
{
if(*p=='