In LCD 4-bit Mode Interfacing we need to connect only 4+3 wire to LCD from Microcontroler . So we save 4 pins of micro controller.But we need to send 8 bit data or command to lcd by using 4 wire How ? By spiting the data or command into two parts (4 bit nibble) ie ,lower 4 bits and higher 4 bits (the technique is called masking ). We need first initialize the LCD as 4 bit according to the data sheet .that is as followsPowering LCD .Wait for abour 20mSSend the first init value (0x30) Wait for about 10mSSend second init value (0x30) Wait for about 1mSSend third init value (0x30)Wait for 1mSSelect bus width (0x20) so we give 0x20 and selected as 4 bit modeWait for 1mSThen, we send higher4bit and then lower 4bit . This means in both command and data sending function we need to separate the higher 4-bits and lower 4-bits.
Send to the LCD port (that to 4 pins of the LCD )
Send enable signal
Mask higher 4-bits
Send to LCD port
Send enable signal
Programming section as follows
I am using the controller 8051 with the compailer Keil and with C language .
The port 2 of the 8051 is used . the circuit as follows
#include"delay.h"
#define LCDPORT P2 // named the Port2 as LCDPORT
sbit RS=LCDPORT^2; // P2.2 named RS
sbit E=LCDPORT^3; // P2.3 named as E
#define LINE2 lcd_cmd(0xc0); // used to display the second line oxc0 is
void latch(void) // used to a high to low pulse the pin E
{
E = 1;
delay(1);
E = 0;
}
void lcd_cmd(unsigned char c) // used to send the command / Instruction to the lcd port
{
RS = 0; // send a '0' value to select to send command
delay(1);
LCDPORT = c & 0xf0; // send the command c only 4 bit by masking the lower bit
latch();
delay(1);
LCDPORT = (c << 4); // giving the lowerbit by shifting the 4 bit to left
latch();
}
void lcd_data(unsigned char c)
{
RS =1; // send 1 to send data
delay(1);
LCDPORT = c & 0xf0 | 0x4; //send the data only 4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
delay(1);
latch();
LCDPORT = (c << 4)| 0x4; ; // giving the lower bit by shifting the 4 bit to left
latch();
}
void lcd_init()
{
delay(20);
lcd_cmd(0x30); //as per data sheet
delay(20);
lcd_cmd(0x30); //as per data sheet
delay(4);
lcd_cmd(0x32); //as per data sheet
delay(4);
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x0c); // Make cursorinvisible
lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
}
void string(const char *q) // used to send single charcter to display the lcd
{
while (*q) {
lcd_data(*q++);
}
}
Finaly The code is lcd.c
#include <REGX51.H>
#include "lcd.h"
void main(){
lcd_init();
string("Lcd Testing ");
LINE2
string("its displaying ");
while(1);
}
Download the full project including Proteus File Clik here
In LCD 4-bit Mode Interfacing we need to connect only 4+3 wire to LCD from Microcontroler . So we save 4 pins of micro controller.But we need to send 8 bit data or command to lcd by using 4 wire How ?
By spiting the data or command into two parts (4 bit nibble) ie ,lower 4 bits and higher 4 bits (the technique is called masking ).
We need first initialize the LCD as 4 bit according to the data sheet .
that is as follows
Powering LCD .
Wait for abour 20mS
Send the first init value (0x30)
Wait for about 10mS
Send second init value (0x30)
Wait for about 1mS
Send third init value (0x30)
Wait for 1mS
Select bus width (0x20) so we give 0x20 and selected as 4 bit mode
Wait for 1mS
Then, we send higher4bit and then lower 4bit . This means in both command and data sending function we need to separate the higher 4-bits and lower 4-bits.
Send to the LCD port (that to 4 pins of the LCD )
Send enable signal
Mask higher 4-bits
Send to LCD port
Send enable signal
Programming section as follows
I am using the controller 8051 with the compailer Keil and with C language .
The port 2 of the 8051 is used . the circuit as follows
#include"delay.h"
#define LCDPORT P2 // named the Port2 as LCDPORT
sbit RS=LCDPORT^2; // P2.2 named RS
sbit E=LCDPORT^3; // P2.3 named as E
#define LINE2 lcd_cmd(0xc0); // used to display the second line oxc0 is
void latch(void) // used to a high to low pulse the pin E
{
E = 1;
delay(1);
E = 0;
}
void lcd_cmd(unsigned char c) // used to send the command / Instruction to the lcd port
{
RS = 0; // send a '0' value to select to send command
delay(1);
LCDPORT = c & 0xf0; // send the command c only 4 bit by masking the lower bit
latch();
delay(1);
LCDPORT = (c << 4); // giving the lowerbit by shifting the 4 bit to left
latch();
}
void lcd_data(unsigned char c)
{
RS =1; // send 1 to send data
delay(1);
LCDPORT = c & 0xf0 | 0x4; //send the data only 4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
delay(1);
latch();
LCDPORT = (c << 4)| 0x4; ; // giving the lower bit by shifting the 4 bit to left
latch();
}
void lcd_init()
{
delay(20);
lcd_cmd(0x30); //as per data sheet
delay(20);
lcd_cmd(0x30); //as per data sheet
delay(4);
lcd_cmd(0x32); //as per data sheet
delay(4);
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x0c); // Make cursorinvisible
lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
}
void string(const char *q) // used to send single charcter to display the lcd
{
while (*q) {
lcd_data(*q++);
}
}
Finaly The code is lcd.c
#include <REGX51.H>
#include "lcd.h"
void main(){
lcd_init();
string("Lcd Testing ");
LINE2
string("its displaying ");
while(1);
}
Download the full project including Proteus File Clik here
Array Variable (declared as Global) and changing the value inside a function -C programming
#include<stdio.h>
int a[3] ={10,15,20}; // declaring array variable as global
int test_function(); // a function to change the array varriable value in side the function
int main()
{
int i,j;
for(i=0;i<3; i++)
printf("Inside the main function i = %d\n",a[i]);
test_function();
printf("\n\n");
for(i=0;i<3; i++)
printf("Inside the test function i = %d\n",a[i]);
return 0;
}
int test_function()
{
a[0] = 18;
a[1] = 100;
a[2] = 250;
return 0;
}
Output and program image
Array Variable (declared as Global) and changing the value inside a function -C programming
#include<stdio.h>
int a[3] ={10,15,20}; // declaring array variable as global
int test_function(); // a function to change the array varriable value in side the function
int main()
{
int i,j;
for(i=0;i<3; i++)
printf("Inside the main function i = %d\n",a[i]);
test_function();
printf("\n\n");
for(i=0;i<3; i++)
printf("Inside the test function i = %d\n",a[i]);
return 0;
}
int test_function()
{
a[0] = 18;
a[1] = 100;
a[2] = 250;
return 0;
}
Output and program image
LED Blinking program by using Mikro (PIC 16F877)
void main() {
TRISB = 0; //Makes PORTB0 or RB0 Output Pin
while(1) //Infinite Loop
{
PORTB = 0x55; //LED ON
Delay_ms(1000); //1 Second Delay
PORTB = 0xAA; //LED OFF
Delay_ms(1000); //1 Second Delay
}
}
LED Blinking program by using Mikro (PIC 16F877)
void main() {
TRISB = 0; //Makes PORTB0 or RB0 Output Pin
while(1) //Infinite Loop
{
PORTB = 0x55; //LED ON
Delay_ms(1000); //1 Second Delay
PORTB = 0xAA; //LED OFF
Delay_ms(1000); //1 Second Delay
}
}
LED Blinking program by Using Atmega32 - Atmel Studio 6
#ifndef F_CPU // defining clock speed of the processor
#define F_CPU 16000000UL // 16 MHz clock speed
#endif
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRC = 0xFF; //Nakes PORTC as Output
while(1) //infinite loop
{
PORTC = 0xFF; //Turns ON All LEDs
_delay_ms(30); //1 second delay
PORTC= 0x00; //Turns OFF All LEDs
_delay_ms(30); //1 second delay
}
}
LED Blinking By using 8051 in Keil IDE
LED Blinking using PIC 16f877a
LED Blinking program by Using Atmega32 - Atmel Studio 6
#ifndef F_CPU // defining clock speed of the processor
#define F_CPU 16000000UL // 16 MHz clock speed
#endif
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRC = 0xFF; //Nakes PORTC as Output
while(1) //infinite loop
{
PORTC = 0xFF; //Turns ON All LEDs
_delay_ms(30); //1 second delay
PORTC= 0x00; //Turns OFF All LEDs
_delay_ms(30); //1 second delay
}
}
LED Blinking By using 8051 in Keil IDE
LED Blinking using PIC 16f877a
compiler - sdcc ,XC8.
#define _XTAL_FREQ 8000000 // setting the crystal frequency
#include <xc.h> // Header file inclusion ,to add function like _delay_ms()
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF // FLASH Program Memory Code Protection bits (Code protection off)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low Voltage In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EE Memory Code Protection (Code Protection off)
#pragma config WRT = ON // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)
int main()
{
TRISB0 = 0; //RB0 as Output PIN
while(1) // endless loop
{
RB0 = 1; // LED ON
__delay_ms(1000); // 1 Second Delay
RB0 = 0; // LED OFF
__delay_ms(1000); // 1 Second Delay
}
return 0;
}
LED Blinking By using 8051 in Keil IDE
/led-blinking-program-by-using-atmega32
compiler - sdcc ,XC8.
#define _XTAL_FREQ 8000000 // setting the crystal frequency
#include <xc.h> // Header file inclusion ,to add function like _delay_ms()
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF // FLASH Program Memory Code Protection bits (Code protection off)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low Voltage In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EE Memory Code Protection (Code Protection off)
#pragma config WRT = ON // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)
int main()
{
TRISB0 = 0; //RB0 as Output PIN
while(1) // endless loop
{
RB0 = 1; // LED ON
__delay_ms(1000); // 1 Second Delay
RB0 = 0; // LED OFF
__delay_ms(1000); // 1 Second Delay
}
return 0;
}
LED Blinking By using 8051 in Keil IDE
/led-blinking-program-by-using-atmega32
sbit LED1 = P2^0; // P2.0 of the pin name cahnged to LED1
void delay(); // a delayis used to give some delay in between turn ON and OFF
void main()
{
while(1)
{
LED1 = 0;
delay();
LED1 = 1 ;
delay();
}
}
void delay()
{
int j;
for(j=0; j<500; j++)
;
}
sbit LED1 = P2^0; // P2.0 of the pin name cahnged to LED1
void delay(); // a delayis used to give some delay in between turn ON and OFF
void main()
{
while(1)
{
LED1 = 0;
delay();
LED1 = 1 ;
delay();
}
}
void delay()
{
int j;
for(j=0; j<500; j++)
;
}
Next Page TCP/IP layers
- recall the 5-layer model above
- the network interface layer is often called the link layer
- we use the generic term packet for each block of data transmitted
- recall that each layer adds its own header, so nature of "packet" varies
- so in fact the following terms are usually used for "packets" at each layer
- frames at the link layer
- datagrams at the internet layer
- segments at the transport layer
- we focus on the transport layer in this section
16x2 LCD Interfacing with STM32,STM32F103C6 lcd_init(); LCD_LINE1; lcd_String(" GeElectron"); LCD_LINE2; lc...