5054 views|1 replies

1379

Posts

0

Resources
The OP
 

Source code of LCD2004 driven by ATmega16 [Copy link]

* ===========================================================
20x4 character LCD main program, compilation software (ICCAVR_6.31) CPU internal
crystal oscillator 8M data lines
B0~B7 are connected to PORTB, E=D7 RW = D6 RS = D5
=== ... PB0|--------7|D0 LCD20x4 | PB1|--------8|D1 | PB2|--------9|D2 | PB3|-------10|D3 | PB4|-------11|D4 | PB5|-------12|D5 | PB6|-------13|D6 | PB7|-------14|D7 | | | | | --15|+LED | | --16|-LED | _______________| |______________| ============================================================*/ #include<ioM16V.h> //CPU_ATmmega16L #define RS_H asm("sbi 0x12,5") //RS is set to high level #define RS_L asm("cbi 0x12,5") //RS is set to low level #define RW_H asm("sbi 0x12,6") //RW is set to high level #define RW_L asm("cbi 0x12,6") //RW is set to low level #define E_H asm("sbi 0x12,7") //E is set to high level #define E_L asm("cbi 0x12,7") //E is set to low level //========================================================== //Microsecond delay program void delay_us(int time) { do { time--; } while (time > 1); } //========================================================= //Millisecond delay program void delay_ms(unsigned int time) { while(time != 0) { delay_us(1000); time--; } } //=========================================================== //Read whether the LCD is in internal operation (busy) status char Lcd_Busy() { char r; DDRB = 0x00; //Port B is set to input mode E_L;RS_L;RW_H; //E=0(enable),RS=0(command),RW=1(read) delay_us(2); //LCD delay subroutine E_H; delay_us(2); //LCD delay subroutine r = PINB & 0x80; //Read the eighth bit of lcd_data E_L;
































































DDRB=0xff; //Port B is set to output modereturn
r; //Read result and return
}

//==========================================================
//Send command program to LCDvoid
Lcd_Command(unsigned char Command)
{
while(Lcd_Busy()); //Judge whether LCD is in internal operation stateE_L
;RS_L;RW_L; //E=0(enable),RS=0(command),RW=0(write)
delay_us(2); //LCD delay subroutine
E_H;
PORTB = Command; //Send command to
LCDdelay_us(2); //LCD delay subroutineE_L
;
}

//=======================================================
//Program to write a character to the LCD
void Lcd_Write(unsigned char Data)
{
while(Lcd_Busy()); //Judge whether the LCD is in internal operation status
E_L;RS_H;RW_L; //E=0(enable),RS=1(data),RW=0(write)
delay_us(2); //LCD delay subroutine
E_H;
PORTB = Data; //Write a character to the LCD
delay_us(2); //LCD delay subroutine
E_L;
}


/*==========================================================
LCD line 1 displays address 1~20 (0x80~0x93)
LCD line 2 displays address 1~20 (0xc0~
0xd3) LCD line 3 displays address 1~20 ( 0x94 ~0xa7) LCD line 4 displays address 1
~20 (0xd4~ 0xe7 ) ===
... Lcd_Command(0x38); // Lcd_Command(0x08); //Set the display off Lcd_Command(0x01); //Clear the display Lcd_Command(0x06); //Set the LCD to automatically increase the AC by 1 after receiving 1Byte of data Lcd_Command(0x0C); //Set the cursor, 0x0c=no display, 0x0d=flash display. } //=========================================================== //Write ASCII string program void asc_tran(unsigned char *asc) { while((*asc) != 0) //Judge whether the word ends { Lcd_Write(*asc); //Write a string to the LCD asc++; //Move to the next character } } //======================================================== //Test main LCD main program void main() { Lcd_Init(); //Initialize LCD while(1) { Lcd_Command(0x83); //Set display address asc_tran("-----@_@------"); //Display string Lcd_Command(0x97); //Set display address asc_tran("www.ouravr.com"); //Display string delay_ms(1000); //Delay 1 second Lcd_Command(0x01); //Clear display Lcd_Command(0x83); //Set display address









































asc_tran("-----^_^------"); //Display string
Lcd_Command(0x94); //Set display address
asc_tran("http://59.36.96.196"); //Display string
delay_ms(1000); //Delay
Lcd_Command(0x01); //Clear display
}
}
This post is from Microchip MCU

Latest reply

You can use it directly! You are such a good person @! Selfless person!  Details Published on 2008-5-2 12:30
 

4

Posts

0

Resources
2
 
You can use it directly! You are such a good person @! Selfless person!
This post is from Microchip MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list