Microcontroller LCD Experiment 1

Publisher:SparkStar22Latest update time:2016-04-18 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
code show as below:
//filename:global.h
#include
 
//#include
//#include
 
#define uchar unsigned char
#define uint unsigned int
 
//filename:T6963C.H
#define DATA_PORT P0
//-------------------------------------------
//              Pin definition   
//------------------------------------------
sbit CD=P2^0;    //Data (L)/Command (H) selection
sbit WRIT=P2^1;    //write, low level is valid
sbit CE=P2^2;    //Enable, low level is effective
//===========================================
//              Function declaration
//-------------------------------------------
void delay_lcd(char);
void write_data(char);
void write_text(char);
void write_com(char);
void clr_lcd(char,char,int);
void lcd_init_graph();
void lcd_init_text();
void text_out(char a);
int asc2lcd(int asc);
//--------------------------------------------
//              Write data function
//--------------------------------------------
void write_data(char dat){
CD=0;          //data
CE=0;          //LCD enable
WRIT=0;        //write
DATA_PORT=dat; //Send data to port P
delay_lcd(1);      //Add delay when the crystal oscillator is high
WRIT=1;        //Close writing
CE=1;          //disable enable
}
//--------------------------------------------
//              Write data function
//--------------------------------------------
void write_text(char text){
CD=0;          //data
CE=0;          //LCD enable
WRIT=0;        //write
DATA_PORT=text; //Send data to port P
delay_lcd(1);      //Add delay when the crystal oscillator is high
WRIT=1;        //Close writing
CE=1;          //disable enable
}
//--------------------------------------------
//              Write command function
//--------------------------------------------
void write_com(char com){
CD=1;    //command
CE=0;
WRIT=0;
DATA_PORT=com;
delay_lcd(1);    //Add delay when the crystal oscillator is high
WRIT=1;
CE=1;
}
void clr_lcd(char x,char y,int length){
int i,place;
place=x*30+y;
write_data(place&0xff);
write_data(place/256);
write_com(0x24);        //Set
for(i=0;i
write_data(0xff);          //Write a space and clear the screen
write_com(0xb2);        //turn off automatic writing
}
//--------------------------------------------
//        LM4229 initialization function
//--------------------------------------------
void lcd_init_graph(){
write_data(0);        //Graphics first address
write_data(0);
write_com(0x42);    //Set the first address of the graphics 
write_data(30);
write_data(0);
write_com(0x43);    //Graphics area settings
write_com(0x80);    //Set to OR mode
write_com(0x98);    //Turn off text display and turn on graphic display
}
//--------------------------------------------
//        LM4229 initialization function
//--------------------------------------------
void lcd_init_text(){
write_data(0); 
write_data(0);
write_com(0x40);     //set text home address
write_data(30);  
write_data(0);
write_com(0x41);     //set text area;
write_com(0x84);     //text attribute mode
write_com(0x94);    //text on graphic off
}
void cursor_on(){
write_com(0xA0);
write_com(0x93);
write_com(0x94);    //text on graphic off
}
void print_text(char x,char y,char a){
int place;
place=x*30+y;
write_data(place&0xff);   //write address lower 8 bits
write_data(place/256);    //write address high 8 bits
write_com(0x24);      //Set address
write_com(0xb0);      //Set data to be written automatically
write_text(a);
write_com(0xb2);      //Automatic reset
}
void text_out(char a){
write_com(0xb0);      //Set data to be written automatically
write_text(a);
write_com(0xb2);      //Automatic reset
}
void text_location(int place){
write_data(place&0xff);   //write address lower 8 bits
write_data(place/256);    //write address high 8 bits
write_com(0x24);      //Set address
}
void print_string(char* str){
int i;
int ch;
for(i=0;str[i]!=0;i++)
{
ch=asc2lcd(str[i]);
text_out(ch);
}
}
//--------------------------------------------
//              Delay function
//--------------------------------------------
void delay_lcd(uchar t){
for(;t!=0; t--);
}
//===================================================
int asc2lcd(int asc){
uint r;
r=asc-32;
return r;
}
//latest revise:2010-2-11
//by:alex shoal
//email:alex.shoal@gmail.com
 
main(){  
int place=5;
char ch=0x00;
lcd_init_text();
text_location(place);
print_string("Hello,china! ");
while(1);
}

Keywords:MCU Reference address:Microcontroller LCD Experiment 1

Previous article:Microcontroller LCD Experiment 2
Next article:Microcontroller keyboard scanning experiment

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号