8051 Design & Development Section
Download-The 8051 Microcontroller and Embedded Systems Using Assembly and C by Mazidi
HAPPY NEW YEAR MESSAGE DISPLAY PROGRAM and SIMULATION Download here.....
8051 Microcontroller tutorials.....8051 Microcontroller
USART_Serial Examples_By Krishna Gaihre.......
Custom character generation on 16x2 LCD using 8051 microcontroller
Download Custom Character generation at :Download Here
1. Introduction:
In this tutorial, we learn how to create or design custom characters on 16x2 LCD using 8051 microcontroller. Before going to discuss custom characters design on LCD, we will see how the standard characters (which are already stored in LCD memory during manufacture) are displayed on the 16x2 LCD.
2. Displaying standard characters on LCD:
In 16x2 LCD controller HD44780, there are three memory locations are available to store characters, numbers and special symbols.
1. Display data RAM (DDRAM).
2. Character Generator ROM (CGROM).
3. Character Generator RAM (CGRAM). Power failure data loss
Out of these three memory locations, DDRAM and CGROM are used to generate regular standard characters (ASCII characters). By using these three memory locations, a user can generate different character fonts and symbols on LCD display. A character font describes the shape and style of the character. Each shape of a character is designed by taking the number of pixels in mind. For example, in 16x2 LCD there are 16 segments available per single line. Each segment contains pixels in 5x7 or 5x10 matrix forms.
For example, a character in both uppercase ‘A’ and lowercase ‘a’ is designed by making corresponding pixels into black (no light) as shown in figure 1.1,
![]() |
Figure 1.1 shows the uppercase and lowercase formats of character ‘A’ in 5x7 matrix of LCD display. |
In each row, the ON and OFF pixels of 5x7 matrix is represented by binary values 1 and 0 respectively, from these binary values the hexadecimal code is designed by gathering all 1’s and 0’s as shown in the figure 1.1. All these eight hexadecimal codes (referred as character pattern) of each character are stored in memory. LCD Manufacturers store these hexadecimal representation codes of all ASCII characters in character generator ROM (CGROM) area as shown in figure1.2. We refer the hexadecimal codes in CGROM as standard or basic fonts of characters in LCD.
![]() | |||||||
Figure 1.2 shows Standard ASCII characters stored in CGROM and equivalent ASCII code in hexadecimal is presented as address of that particular character. |
2.1. How to generate custom character ?
I am going to explain custom character generation using an example. In the figure 2, first character displayed on the LCD is named 'Curvy Object' in the code. To generate this character, First make a box of 8 by 5 dots. Then fill the dots required to make the custom character you want to display. Following figure explains this concept.We can program 8 custom characters when we are using 5x8 font in the LCD settings. And we can program 4 custom characters when we are using 5x10 font in the LCD settings. I have used 5x8 font in the code, hence at most 8 custom characters can be programmed. Using the approach to make the custom character described above, 2 custom characters were defined in the code. These custom character arrays are shown below[2].
2.2. The Display Data RAM (DDRAM) stores the ASCII code of a character which is sent by the microcontroller. Now the LCD controller (HD44780) maps the corresponding ASCII code in DDRAM with CGROM address to bring the hexadecimal codes (character pattern) of that particular character. By using those hexadecimal codes the 5x7 matrix segment will light according to that character pattern to display corresponding character on it as shown in figure 1.3.
![]() |
Figure 1.3 block diagram shows character generation on LCD. |
3. Creating and displaying Custom Characters on LCD display:
To create custom characters on LCD, the display controller (HD44780) make use of CGRAM area to store hexadecimal codes (character pattern) which are designed by user. In addition to CGRAM area, DDRAM area is also used to store the CGRAM address of a particular character which is sent by microcontroller in hexadecimal format.
Don’t confuse with the above section of this tutorial “Displaying standard characters on LCD”, in which DDRAM and CGROM memory areas are used to generate regular standard characters. But here, to create and display custom characters on LCD, we use DDRAM and CGRAM (both are RAM’s).
There are only 8 memory locations are available to store user defined characters in CGRAM with address 0x01 (00000001n) – 0x07 (01100001b), which is shown in the figure 1.2 by highlighting locations with green color.
3.1 Steps to create and display custom character on 16x2 LCD using microcontroller
1. To create custom characters, first draw a table with 7 rows and 5 columns (5x7 matrix) on a paper. Fill the corresponding squares with some color according to your style of custom character pattern and form the hexadecimal code for each row as shown in figure 1.1.
2. Initialize LCD with required commands.
3. Send the Initial address (0x40) of CGRAM as a command to LCD to store the custom character. The next address to store another custom character should be ‘0x48’. That means we should add eight bytes to the present address to get the next address of CGRAM.
4. Send the all hexadecimal bytes of custom character to CGRAM.
5. Force the LCD cursor to where you want to display your custom character. If it is beginning of 1st line, then send ‘0x80’ as command.
6. Send the position of your custom character in CGRAM to LCD.
4. C code to display single custom character program ver1.1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
| /**********************************************************************************************************************/ // Author - Krishna gaihre // LCDwithDelay.c - Generating single custom character on 16x2 LCD using 89s52 microcontroller -- program v 1.1 // Note: no need provide external delay after command or data, because the send_cmd and send_data functions it self // provide 1 milliseconds after enable pulse /**********************************************************************************************************************/ /********************************************** Header Files Declaration **********************************************/ #include<reg52.h> #include<stdio.h> #include<intrins.h> /********************************************* LCD control signals declaration ****************************************/ sbit RS = P2^0; // Register Select line sbit RW = P2^1; // Read/write line sbit Enable = P2^2; // Enable line #define LCD_PORT P0 // define port /********************************************* LCD function prototypes ************************************************/ void LCD_init( void ); void send_cmd(unsigned char ); void send_char(unsigned char ); void send_String(unsigned char *); void delayms(unsigned int ); void CustomCharacterStore( void ); /********************************Character array to hold custom character patterns*************************************/ unsigned char CharacterArray[8] = {0x0E,0x11,0x0E,0x04,0x1F,0x04,0x1B,0x00}; /********************************************* Main Funciton declaration **********************************************/ void main() { LCD_PORT = 0x00; // Make the port as output port /****************** Reset process from datasheet **************/ delayms(15); // <span class="IL_AD" id="IL_AD7">wait</span> for more than 15ms after supply rises to 4.5V send_cmd(0x30); delayms(4); // wait more than 4.1ms send_cmd(0x30); delayms(1); // wait more than 100us, but delayms(1) will provide 1ms send_cmd(0x30); delayms(1); send_cmd(0x02); // return to home delayms(1); /****************** Initialize LCD **************/ LCD_init(); // LCD initialization CustomCharacterStore(); while (1) { send_cmd(0x83); // Force cursor to beginning of 1st line, if the number is 0x83 then force the cursor to 53rd position send_char(0x00); // locate the first character in CGRAM } } void CustomCharacterStore() { unsigned char i=0,j=0; send_cmd(0x40); //Load the location where we want to store /**Store the custom character pattern in CGRAM area**/ send_char(0x0E); //Load row 1 data send_char(0x11); //Load row 2 data send_char(0x0E); //Load row 3 data send_char(0x04); //Load row 4 data send_char(0x1F); //Load row 5 data send_char(0x04); //Load row 6 data send_char(0x1B); //Load row 7 data send_char(0x00); //Load row 8 data, this 8th won't display on LCD, because the matrix is 5x7 } /********************************************* LCD Initialization Function declaration ********************************/ void LCD_init() { send_cmd(0x38); // configuring LCD as 2 line 5x7 matrix in 8-bit mode send_cmd(0x0C); // Display on, Cursor blinking send_cmd(0x01); // Clear Display Screen send_cmd(0x06); // Increment Cursor (Right side) } /******************************************* LCD single character sending Function declaration************************************/ void send_char(unsigned char character) { LCD_PORT = character; RS = 1; // Select Data Register RW = 0; // write operation Enable = 1; // High to Low pulse provided on the enable pin with nearly 1ms(>450ns) delayms(1); // 1 millisec delay Enable = 0; delayms(1); // 1 millisec delay } /*********************************************LCD Command Sending Function declaration********************************/ void send_cmd(unsigned char Command) { LCD_PORT = Command; RS = 0; // Select Command Register RW = 0; // write operation Enable = 1; // High to Low pulse provided on the enable pin with nearly 1ms(>450ns) delayms(1); // 1 millisec delay Enable = 0; delayms(1); // 1 millisec delay } /******************************************* LCD String sending Function declaration*************************************/ void send_String(unsigned char *String) { unsigned char i=0; while (String[i]!= '\0' ) { LCD_PORT = String[i++]; RS = 1; // Select Data Register RW = 0; // write operation Enable = 1; // High to Low pulse provided on the enable pin with nearly 1ms(>450ns) delayms(1); // 1 millisec delay Enable = 0; delayms(1); // 1 millisec delay if (i>=16) // If the number of characters in the string > 16, then the below command automatically send_cmd(0x1C); // Shift the display right side delayms(100); // 100 millisec delay } } /******************************************* delayms Function declaration***********************************************/ void delayms(unsigned int value) { unsigned int i,j; for (i=0;i<=value;i++) { for (j=0;j<100;j++) _nop_(); // no operation produce 1us time delay } }
|
4.1 Output in proteus software for the program1.1:
![]() |
Figure 1.4 displaying animated boy on LCD using proteus simulation software |
5. C code to display more than one custom character using pointers:
In this code I have the changed CustomCharacterStore() function, which is allowed to store 1 to 8 custom characters in CGRAM with the help of pointers concept in C language. And I have created a two dimensional array to define custom character patterns and in the main function, each character is called separately using send_char() function.
5.1 C code to display eight custom characters – program ver1.2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
| /***************************************************************************************************************************/ // Author - Krishna gaihre // LCDwithDelay.c - Generation of custom characters on 16x2 LCD using 89s52 microcontroller // Note: no need provide external delay after command or data, because the send_cmd and send_data functions it self // provide 1 milliseconds after enable pulse /***************************************************************************************************************************/ /********************************************** Header Files Declaration ***************************************************/ #include<reg52.h> #include<stdio.h> #include<intrins.h> /********************************************* LCD control signals declaration ***************************************************/ sbit RS = P2^0; // Register Select line sbit RW = P2^1; // Read/write line sbit Enable = P2^2; // Enable line #define LCD_PORT P0 // define port /********************************************* LCD function prototypes ************************************************/ void LCD_init( void ); void send_cmd(unsigned char ); void send_String(unsigned char *); void send_char(unsigned char ); void delayms(unsigned int ); void CustomCharacterStore( void ); /********************************Character array to hold custom character patterns*************************************/ unsigned char CharacterArray[8][8] = {{0x0E,0x11,0x0E,0x04,0x1F,0x04,0x1B,0x00}, // boy {0x00,0x00,0x1E,0x13,0x13,0x0C,0x1F,0x00}, // cup {0x00,0x0A,0x0A,0x00,0x11,0x0E,0x06,0x00}, // simley {0x00,0x00,0x1B,0x1F,0x0E,0x04,0x00,0x00}, // love {0x00,0x19,0x1A,0x04,0x0B,0x13,0x00,0x00}, // percentage {0x1F,0x11,0x0A,0x04,0x0A,0x15,0x1F,0x00}, // hour glass {0x00,0x1B,0x15,0x11,0x11,0x1F,0x00,0x00}, // mail folder {0x00, 0x0E, 0x11, 0x1F, 0x15, 0x1F, 0x0A}}; // android robo /********************************************* Main Funciton declaration ***********************************************/ void main() { LCD_PORT = 0x00; // Make the port as output port /****************** Reset process from datasheet **************/ delayms(15); // wait for more than 15ms after supply rises to 4.5V send_cmd(0x30); delayms(4); // wait more than 4.1ms send_cmd(0x30); delayms(1); // wait more than 100us, but delayms(1) will provide 1ms send_cmd(0x30); delayms(1); send_cmd(0x02); // return to home delayms(1); /****************** Initialize LCD **************/ LCD_init(); // LCD initialization CustomCharacterStore(); while (1) { send_cmd(0x80); // Force cursor to beginning of 1st line, if the number is 0x83 then force the cursor to 53rd position send_char(0x00); // locate the first character in CGRAM send_char( ' ' ); // space send_char(0x01); // locate the second character in CGRAM send_char( ' ' ); // space send_char(0x02); // locate the third character in CGRAM send_char( ' ' ); // space send_char(0x03); // locate the fourth character in CGRAM send_char( ' ' ); // space send_char(0x04); // locate the fifth character in CGRAM send_char( ' ' ); // space send_char(0x05); // locate the sixth character in CGRAM send_char( ' ' ); // space send_char(0x06); // locate the seventh character in CGRAM send_char( ' ' ); // space send_char(0x07); // locate the eigth character in CGRAM send_char( ' ' ); // space } void CustomCharacterStore() { unsigned char i=0,j=0; //send_cmd(0x48); //Load the location where we want to store //delayms(1); // Delay of 1millisec /**Store the custom character patterns in CGRAM area**/ while (j<8) { send_cmd(0x40 + (j*8)); for (i=0;i<8;i++) { send_char(CharacterArray[j][i]); } j++; } } /********************************************* LCD Initialization Function declaration ********************************/ void LCD_init() { send_cmd(0x38); // configuring LCD as 2 line 5x7 matrix in 8-bit mode send_cmd(0x0C); // Display on, Cursor blinking send_cmd(0x01); // Clear Display Screen send_cmd(0x06); // Increment Cursor (Right side) } void send_char(unsigned char character) { LCD_PORT = character; RS = 1; // Select Data Register RW = 0; // write operation Enable = 1; // High to Low pulse provided on the enable pin with nearly 1ms(>450ns) delayms(1); // 1 millisec delay Enable = 0; delayms(1); // 1 millisec delay } /*********************************************LCD Command Sending Function declaration********************************/ void send_cmd(unsigned char Command) { LCD_PORT = Command; RS = 0; // Select Command Register RW = 0; // write operation Enable = 1; // High to Low pulse provided on the enable pin with nearly 1ms(>450ns) delayms(1); // 1 millisec delay Enable = 0; delayms(1); // 1 millisec delay } /******************************************* delayms Function declaration***********************************************/ void delayms(unsigned int value) { unsigned int i,j; for (i=0;i<=value;i++) { for (j=0;j<100;j++) _nop_(); // no operation produce 1us time delay } }
|
5.2 Output in proteus software for program 1.2
![]() | ||||||||
Figure 1.5 displaying different animated custom characters on LCD using proteus simulation software. |
PIC/AVR Design & Development Section
AVR Tutorials...Here
Download-The AVR Microcontroller and Embedded Systems By Mazadi
PIC Tutorials...PIC Microcontroller
Download-PIC Microcontroller and Embedded Systems Book - Mazidi...comming soon
The PIC Microcontroller Your Personal Introductory Course By John Morton Download
PIC Tutorials:-MPLAB IDE Getting Started Tutorial Video
LED Interfacing and Toggling their states with PIC18F4550 Miro-Controller.Embedded system with AVR
Embedded programming using ATMEGA 16:Here i am going to tell you about the embedded programming using Atmega16 microcontroller with c language.This is very easy.
In the below your seeing the Pin out of Atmega-16.
To start C programming language on Atmel AVR Microcontroller you need to download these following tools:
- Down load the latest Atmel AVR Studio which provide you with the complete IDE (integrated development environment) for managing project, program editing, compiling, debugging and downloader for all Atmel AVR Microcontroller series.
- The Atmel AVR Studio only provide you with native microcontroller language (assembler), so you need to down load the WinAVR Project which provide you with AVR GCC (GNU C Compiler for AVR Microcontroller) base compiler and library for window environment. This AVR GCC is fully integrated and supported by Atmel AVR Studio.
To create your first AVR project go to Start -> All Programs -> Atmel AVR Tools -> AVR Studio 4, this will launch the AVR Studio 4 application and the Welcome to AVR Studio 4 form appear, click on the New Project button and it will show the Create new project screen as follow:
On Project Type choose AVR GCC, enter myfirstc for the project name and you could also change the project location directory as you like, then click on the Next>> button, you will be asked for debugging platform on the following screen:
Choose AVR Simulator for debug platform and ATmega16 for the device, then click on the Finish button. This will create all the necessary files and directories needed for this project. Now the AVR Studio 4 IDE is ready and display the empty myfirstc.c file.
Enter or cut and paste this source program bellow to the program code windows:
/***************************************************************************
#include
#include
void Wait()
{
uint8_t i=0;
for(;i<23;i++)
_delay_loop_2(0);
}
void main()
{
//Set PORTC0 as output
DDRB=0b00000001;
while(1)
{
//Set Port D=High(+5v)
PORTB=0xff; // in hexadecimal
Wait();
//Set Port D=Low(GND)
PORTB&=0b00000000; // in binary it is 0x00 in hexadecimal
Wait();
}
}
The program start with the standard comment (all the statement start with
double slash is consider as comment in standard C syntax) that give the
information about the program, version and compiler version,etc. The next two
include statement tell the C compiler to include the AVR microcontroller specific library and the delay library when compiling the program.Inside the main
program, first we instruct the AVR microcontroller (i.e. avr/io.h ) to enable
it’s 8 bit PORT-D input/output port for output by setting the data direction
register (DDRB) on PORT-B to 0x01 that is 0b00000001 in binary. Next inside the while(1) loops statement (it’s mean we loop continuously) we
simple instruct the AVR microcontroller to turn on and off all it’s 8 bit
PORT-D by assigning the value 0xFF (on) and 0×00 (off) to the PORT-B register
(PORTB). The 100 millisecond delay is put there so our eye could catch the
process, otherwise the process is so fast that we see the port is always on.
Building the HEX Files:-
Once you have written the code Just press F7 key of your key board to compile and
generate the HEX code.....
Downloading the HEX code to Microcontroller:-
To download the code you need a programmer ckt..in the below i am giving a
ckt dig of a parallel port(BSD) programmer which is very low cost
programmer...you need some simple wire and connectors to make it.
if you have not have a PC then you can make your USB programmer which
is little costlier...You can click here to learn how to make
USB programmer...
Once you have made the programmer connect it to your computer and
download the programmer using the following steps....
Programming Using PonyProg.
This is the programmer we made in the previous tutorial. Its use is simple. Start Ponyprog, you will get a screen similar to this.Fig - Ponyprog main window. |
Fig - Ponyprog Setup |
- Select the hex file you want to program using the File->Open Program(FLASH) file.
- Command->Erase.
- Command->Write Flash
- Command->Verify Program(FLASH)
- If every thing is correct, your MCU is programmed successfully.
- Disconnect programmer from the Target and switch it off.
Hello there, have you by chance considered to publish regarding Nintendo or PS handheld? https://royalcbd.com/product/cbd-oil-500mg/
ReplyDelete