Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
no that are in c language i need in assembly languageI thought I gave you a bit of code in your other thread.... What do you need?
ok can you tell me what is the use of register bank and SFR in ram i think register bank is used to store location of dataRight O... I'll be at home in about an hour...
I'll put a skeletal ASM program together ( actually I already have one ) and post it soon..
ok I will wait for your replyI'll try and explain later... SFR's are at the top of the ram banks 0x80 and up...
RS BIT P3.1 ; LCD
RW BIT P3.2 ; Constants
E BIT P3.0 ;
BZ BIT P1.7 ; busy flag
org 0h ; reset vector
sjmp Start
org 20h ; jump over vectors
;
; Start of code
;---------------------------------
Start:
acall LcdInit ; called once only
While:
acall LcdLine1 ; Goto Line1
mov DPTR,#MSG1
acall LcdPrint ; Display message
acall LcdLine2 ; goto Line2
mov DPTR,#MSG2 ;
acall LcdPrint ; Display message
sjmp While ; forever loop
MSG1:
db "First Line ",0
MSG2:
db "Second Line ",0
;
; Initialize LCD
;---------------------------------
LcdInit:
clr RW
acall delay40Ms
mov P1,#33h ; Init once
setb E
clr E
acall delayMs ; Init twice
setb E
clr E
acall delayMs ; Now busy can be read.
mov a,#38h ; Function set: 8 bits: 2 Line : font 5x7.
acall LcdCom
mov a,#0Ch ; Display On: Cursor Off : Blink Off.
acall LcdCom
mov a,#06h ; Shift forward.
acall LcdCom
mov a,#01h ; Clear Goto position 1.
acall LcdCom
ret
;
; Goto first line
;---------------------------------
LcdLine1:
mov A,#80h ; position 1 on line 1
acall LcdCom
ret
;
; Goto second line
;---------------------------------
LcdLine2:
mov A,#0C0h ; position 1 on line 2
acall LcdCom
ret
;
; Print a null terminated string
;---------------------------------
LcdPrint:
mov A,#0h
movc A,@A+DPTR ; Through string until 0
cjne A,#0,Char ;
ret
Char:
acall LcdData ; Print data character
inc dptr
sjmp LcdPrint
;
; Waiting for LCD module
;---------------------------------
LcdBusy:
mov P1,#0FFh ; tristate the port
clr RS ; command mode
setb RW ; Read flags
busy: clr E
setb E
nop
jb BZ, busy ; wait until ready
clr E
clr RW ; Back to write mode
ret
;
; Send command to LCD module
;---------------------------------
LcdCom: ; sends a command
acall LcdBusy
clr RW
clr RS
mov P1,A ; Acc has command
setb E
clr E
ret
;
; Send data to LCD module
;---------------------------------
LcdData: ; Sends data
acall LcdBusy
clr RW
setb RS
mov P1,A ; Acc has data
setb E
clr E
ret
;
; Delays
;---------------------------------
delay40Ms:
mov R1,#25h ; Simple delay @ 40 milli seconds
dlyM: acall delayMs
djnz R1,dlyM
ret
delayMs:
mov R0,#0h ; Simple delay @ 1.1 milli second
dlyU: nop
nop
djnz R0,dlyU
ret
end
[code]
We'll do some interrupts later..
I just put this together
Its a start at least..
Code:RS BIT P3.1 ; LCD RW BIT P3.2 ; Constants E BIT P3.0 ; BZ BIT P1.7 ; busy flag org 0h ; reset vector sjmp Start org 20h ; jump over vectors ; ; Start of code ;--------------------------------- Start: acall LcdInit ; called once only While: acall LcdLine1 ; Goto Line1 mov DPTR,#MSG1 acall LcdPrint ; Display message acall LcdLine2 ; goto Line2 mov DPTR,#MSG2 ; acall LcdPrint ; Display message sjmp While ; forever loop MSG1: db "First Line ",0 MSG2: db "Second Line ",0 ; ; Initialize LCD ;--------------------------------- LcdInit: clr RW acall delay40Ms mov P1,#33h ; Init once setb E clr E acall delayMs ; Init twice setb E clr E acall delayMs ; Now busy can be read. mov a,#38h ; Function set: 8 bits: 2 Line : font 5x7. acall LcdCom mov a,#0Ch ; Display On: Cursor Off : Blink Off. acall LcdCom mov a,#06h ; Shift forward. acall LcdCom mov a,#01h ; Clear Goto position 1. acall LcdCom ret ; ; Goto first line ;--------------------------------- LcdLine1: mov A,#80h ; position 1 on line 1 acall LcdCom ret ; ; Goto second line ;--------------------------------- LcdLine2: mov A,#0C0h ; position 1 on line 2 acall LcdCom ret ; ; Print a null terminated string ;--------------------------------- LcdPrint: mov A,#0h movc A,@A+DPTR ; Through string until 0 cjne A,#0,Char ; ret Char: acall LcdData ; Print data character inc dptr sjmp LcdPrint ; ; Waiting for LCD module ;--------------------------------- LcdBusy: mov P1,#0FFh ; tristate the port clr RS ; command mode setb RW ; Read flags busy: clr E setb E nop jb BZ, busy ; wait until ready clr E clr RW ; Back to write mode ret ; ; Send command to LCD module ;--------------------------------- LcdCom: ; sends a command acall LcdBusy clr RW clr RS mov P1,A ; Acc has command setb E clr E ret ; ; Send data to LCD module ;--------------------------------- LcdData: ; Sends data acall LcdBusy clr RW setb RS mov P1,A ; Acc has data setb E clr E ret ; ; Delays ;--------------------------------- delay40Ms: mov R1,#25h ; Simple delay @ 40 milli seconds dlyM: acall delayMs djnz R1,dlyM ret delayMs: mov R0,#0h ; Simple delay @ 1.1 milli second dlyU: nop nop djnz R0,dlyU ret end [code] We'll do some interrupts later..
countl equ 20h
counth equ 21h
org 0h ; reset vector
sjmp Start
org 03h ; Ex0 interrupt
sjmp ISR
org 20h ; jump over vectors
;
; Start of code
;---------------------------------
Start:
setb P3.2 ; INT0 as input
setb IT0 ; Set level of interrupt
mov IE,#081h ; Global On : INT0 On..
While:
sjmp While ; forever loop
ISR:
mov A,countl ; get counter low byte
mov B,counth ; get counter high byte
add A,#1 ; increase counter low
jnc non ; are we at 255
inc b ; yes! increase Counter high
non: mov countl,A ; store Low
mov counth,B ; store High
clr IE0 ; ensure flag off.
reti ; return from interrupt..
end