Upload
anjusha-r
View
295
Download
1
Embed Size (px)
Citation preview
8051 Programming
Assembly language----- includes mnemonics
Example: ADD, SUB, MUL, RR…
Assembly Language-----Assembler---Binary
Disadvantage:
We should know about architecture of microcontroller or microcontroller
Higher level languages : c ,java
( c, c++,java)------compiler----binary
Advantage:
No need to consider about architecture of µp/µc….just few features are considered
STEPS FOLLOWED IN CONVERTING SOURCE FILE TO HEX. FILE
EMBEDDED C
DATA TYPES USED IN EMBEDDED C
Integer int x;Unsigned integer unsigned int x;Char char x;Unsigned char unsigned char x;
1) BASIC PORT PROGRAMMING
P0 -------
P0=____________?
MSB LSB
BASIC PORT PROGRAMMING……………………
P0-------8 4 2 1 8 4 2 1
ANS: P0=0X55
Syntax to be followed:
Pin declaration:
sbit variablename = PX ^Y;Where,
x=0,1,2,3 porty=0,1,2,3,4,5,6,7 pins
Example: sbit led = P1^0;
WAP to blink a led which is connected to port2 , pin 0
#include<reg52.h>sbit led = P2^0;unsigned int i;void main()
{P2=0x00;led =1;for(i=0; i<1000; i++);
led =0;for(i=0; i<1000; i++);
}
Syntax to be followed:
port declaration:
#define variablename Px
Where,x=0,1,2,3
Example: #define segment P1
WAP to blink all led’s connected to port2
#include<reg52.h>#define leds P2unsigned int i;void main()
{leds=0x00;for(i=0; i<1000; i++);
leds =0xFF;for(i=0; i<1000; i++);
}
INTRODUCTION TO
KEIL IDE FOR
80XX PROGRAMMING
PROGRAM 1: WAP to blink a led which is connected to port1 , pin 0
PROGRAM 2: WAP to blink the led’s which are connected to port1
PROGRAM 3: WAP to blink the led’s alternatively which are
connected to port1
Practice examples
pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin0
0 0 0 0 0 0 0 10 0 0 0 0 0 1 00 0 0 0 0 1 0 00 0 0 0 1 0 0 00 0 0 1 0 0 0 00 0 1 0 0 0 0 00 1 0 0 0 0 0 01 0 0 0 0 0 0 0
PROGRAM 4:WAP to shift a bit of port1 from pin0 to pin7
PROGRAM 5: WAP to shift a bit of port1 from pin7 to pin0
Pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin01 0 0 0 0 0 0 00 1 0 0 0 0 0 00 0 1 0 0 0 0 00 0 0 1 0 0 0 00 0 0 0 1 0 0 00 0 0 0 0 1 0 00 0 0 0 0 0 1 00 0 0 0 0 0 0 1
PROGRAM 6: WAP to shift a bit of port1 from pin0 to pin7
pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin00 0 0 0 0 0 0 10 0 0 0 0 0 1 10 0 0 0 0 1 1 10 0 0 0 1 1 1 10 0 0 1 1 1 1 10 0 1 1 1 1 1 10 1 1 1 1 1 1 11 1 1 1 1 1 1 1
16X2 LCD Display
8 data pins
3 control pins
supply pins and a potentiometer
1. Two modes
-----Command mode (RS=0)
-----Data mode (RS=1)
2. RW is always logic zero
3. EN=1 to EN=0 for data transfer
LCD INITIALIZATION Using commands
0X38 =========2 lines and 5x7 matrix
0x01 ========= clear the display
0x06 ========= shift cursor to right i.e. increment cursor
0x05 ========= shift display right
0x0E ========= display on, cursor blinking
0x80 ========= force cursor to beginning of first line
0xC0 ========= force cursor to beginning of first line
To pass command to lcd
8datapins = dataRS=0RW=0EN=1Delay()EN=0
To pass command to lcd
8datapins = dataRS=1RW=0EN=1Delay()EN=0
void lcd_cmd(unsigned char d){
dataport =d;rs= 0;rw=0;e=1;delay(150);e=0;delay(150);
} void lcd_data(unsigned char f){
dataport =f;rs= 1;rw=0;e=1;delay(150);e=0;delay(150);
}
Sample code:
WAP to display your name on LCD
Program6:
#include<reg51.h>#define dataport P2 // for LCDvoid delay(int a);void lcd_cmd(unsigned char d);void lcd_data(unsigned char f);sbit rs =P1^0; // rs pin of LCDsbit rw =P1^2; // rw pin of LCDsbit e = P1^1; // enable pin of LCDvoid delay(int a){
int i;for(i=0;i<a;i++);
}
void main(void){lcd_cmd(0x38); //function setdelay(50);lcd_cmd(0x0C); //display on,cursor off,blink off delay(50);lcd_cmd(0x80); //first rowdelay(50);lcd_cmd(0x06); //entry mode, set incrementdelay(50);lcd_cmd(0x80); //first rowdelay(10);dataport=0;P1=0X00;lcd_data('E');delay(10);lcd_data('C');delay(10);lcd_data('E');delay(1500);}