PDA

View Full Version : assembly in Pic



lerameur
- 7th May 2007, 18:05
hello
Below is a program I have with the book I am reading. I am confused with the command to the lcd like ( INITIALIZE LCD PROCEDURE ):
DISPLAY OFF
ENTRY MODE SET
etc..
I know what they do , but they all send 8 bit to the PORTA. How does it know one is for the display and another for the mode entry ? is it an order. it just seem he is sending byte after byte on the same port.
ken


; File name: LCDTest1.asm
; Date: April 13, 2006
; Author: Julio Sanchez
; Processor: 16F84A
;
; Description:
; Program to exercises 8-bit PIC-to-LCD interface.
; Code assumes that LCD is driven by Hitachi HD44780
; controller and that the display supports two lines
; each one with 16 characters. The wiring and base
; address of each display line is stored in #define
; statements. These statements can be edited to
; accomodate a different set-up.
; Program uses delay loops for interface timing.
; WARNING:
; Code assumes 4Mhz clock. Delay routines must be
; edited for faster clock

; Displays: Minnesota State, Mankato
;
;===========================
; switches
;===========================
; Switches used in __config directive:
; _CP_ON Code protection ON/OFF
; * _CP_OFF
; * _PWRTE_ON Power-up timer ON/OFF
; _PWRTE_OFF
; _WDT_ON Watchdog timer ON/OFF
; * _WDT_OFF
; _LP_OSC Low power crystal occilator
; * _XT_OSC External parallel resonator/crystal ocillator
; _HS_OSC High speed crystal resonator (8 to 10 MHz)
; Resonator: Murate Erie CSA8.00MG = 8 MHz
; _RC_OSC Resistor/capacitor ocillator (simplest, 20% error)
; |
; |_____ * indicates setup values

;=========================
; setup and configuration
;=========================
processor 16f84A
include <p16f84A.inc>
__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF

;================================================= ====
; constant definitions
; for PIC-to-LCD pin wiring and LCD line addresses
;================================================= ====
#define E_line 1 ;|
#define RS_line 2 ;| -- from wiring diagram
#define RW_line 3 ;|
; LCD line addresses (from LCD data sheet)
#define LCD_1 0x80 ; First LCD line constant
#define LCD_2 0xc0 ; Second LCD line constant
; Note: The constant that define the LCD display line
; addresses have the high-order bit set in
; order to faciliate the controller command
;
;================================================= ====
; variables in PIC RAM
;================================================= ====
; Reserve 16 bytes for string buffer
cblock 0x0c
strData
endc
; Leave 16 bytes and Continue with local variables
cblock 0x1d ; Start of block
count1 ; Counter # 1
count2 ; Counter # 2
count3 ; Counter # 3
pic_ad ; Storage for start of text area
; (labeled strData) in PIC RAM
J ; counter J
K ; counter K
index ; Index into text table (also used
; for auxiliary storage)
endc

;================================================= ===========
; program
;================================================= ===========
org 0 ; start at address
goto main
; Space for interrupt handlers
org 0x08

main:
movlw b'00000000' ; All lines to output
tris PORTA ; in port A
tris PORTB ; and port B
movlw b'00000000' ; All outputs ports low
movwf PORTA
movwf PORTB
; Wait and initialize HD44780
call delay_5ms ; Allow LCD time to initialize itself
call initLCD ; Then do forced initialization
call delay_5ms ; (Wait probably not necessary)
; Store base address of text buffer in PIC RAM
movlw 0x0c ; Start address of text buffer
movwf pic_ad ; to local variable
;======================
; first LCD line
;======================
; Store 16 blanks in PIC RAM, starting at address stored
; in variable pic_ad
call blank16
; Call procedure to store ASCII characters for message
; in text buffer
movlw d'3' ; Offset into buffer
call storeMN
; Set DDRAM address to start of first line
call line1
; Call procedure to display 16 characters in LCD
call display16
;========================
; second LCD line
;========================
call delay_125mcs ; Wait for termination
call blank16 ; Blank buffer
; Call procedure to store ASCII characters for message
; in text buffer
movlw d'1' ; Offset into buffer
call storeUniv
call line2 ; DDRAM address of LCD line 2
call display16
;=======================
; done!
;=======================
loopHere:
goto loopHere ;done

;************************************************* ***********
; INITIALIZE LCD PROCEDURE
;************************************************* ***********
initLCD
; Initialization for Densitron LCD module as follows:
; 8-bit interface
; 2 display lines of 16 characters each
; cursor on
; left-to-right increment
; cursor shift right
; no display shift
;***********************|
; COMMAND MODE |
;***********************|
bcf PORTA,E_line ; E line low
bcf PORTA,RS_line ; RS line low for command
bcf PORTA,RW_line ; Write mode
call delay_125mcs ;delay 125 microseconds
;***********************|
; FUNCTION SET |
;***********************|
movlw 0x38 ; 0 0 1 1 1 0 0 0 (FUNCTION SET)
; | | | |__ font select:
; | | | 1 = 5x10 in 1/8 or 1/11 dc
; | | | 0 = 1/16 dc
; | | |___ Duty cycle select
; | | 0 = 1/8 or 1/11
; | | 1 = 1/16 (multiple lines)
; | |___ Interface width
; | 0 = 4 bits
; | 1 = 8 bits
; |___ FUNCTION SET COMMAND
movwf PORTB ;0011 1000
call pulseE ;pulseE and delay

;***********************|
; DISPLAY OFF |
;***********************|
movlw 0x08 ; 0 0 0 0 1 0 0 0 (DISPLAY ON/OFF)
; | | | |___ Blink character at cursor
; | | | 1 = on, 0 = off
; | | |___ Curson on/off
; | | 1 = on, 0 = off
; | |____ Display on/off
; | 1 = on, 0 = off
; |____ COMMAND BIT

movwf PORTB
call pulseE ;pulseE and delay

;***********************|
; DISPLAY AND CURSOR ON |
;***********************|
movlw 0x0e ; 0 0 0 0 1 1 1 0 (DISPLAY ON/OFF)
; | | | |___ Blink character at cursor
; | | | 1 = on, 0 = off
; | | |___ Curson on/off
; | | 1 = on, 0 = off
; | |____ Display on/off
; | 1 = on, 0 = off
; |____ COMMAND BIT
movwf PORTB
call pulseE ;pulseE and delay

;***********************|
; ENTRY MODE SET |
;***********************|
movlw 0x06 ; 0 0 0 0 0 1 1 0 (ENTRY MODE SET)
; | | |___ display shift
; | | 1 = shift
; | | 0 = no shift
; | |____ cursor increment mode
; | 1 = left-to-right
; | 0 = right-to-left
; |___ COMMAND BIT
movwf PORTB ;00000110
call pulseE

;***********************|
; CURSOR/DISPLAY SHIFT |
;***********************|
movlw 0x14 ; 0 0 0 1 0 1 0 0 (CURSOR/DISPLAY SHIFT)
; | | | |_|___ don't care
; | |_|__ cursor/display shift
; | 00 = cursor shift left
; | 01 = cursor shift right
; | 10 = cursor and display
; | shifted left
; | 11 = cursor and display
; | shifted right
; |___ COMMAND BIT
movwf PORTB ;0001 1111
call pulseE

;***********************|
; CLEAR DISPLAY |
;***********************|
movlw 0x01 ; 0 0 0 0 0 0 0 1 (CLEAR DISPLAY)
; |___ COMMAND BIT
movwf PORTB ;0000 0001
;
call pulseE
call delay_5ms ;delay 5 milliseconds after init
return
;************************************************* ***********
; DELAY AND PULSE PROCEDURES
;************************************************* ***********
;=======================
; Procedure to delay
; 42 microseconds
;=======================
delay_125mcs
movlw D'42' ; Repeat 42 machine cycles
movwf count1 ; Store value in counter
repeat
decfsz count1,f ; Decrement counter
goto repeat ; Continue if not 0
return ; End of delay
;------------------------------------------------------------
;=======================
; Procedure to delay
; 5 milliseconds
;=======================
delay_5ms
movlw D'41' ; Counter = 41
movwf count2 ; Store in variable
delay
call delay_125mcs ; Delay
decfsz count2,f ; 40 times = 5 milliseconds
goto delay
return ; End of delay
;========================
; pulse E line
;========================
pulseE
bsf PORTA,E_line ;pulse E line
bcf PORTA,E_line
call delay_125mcs ;delay 125 microseconds
return

;=============================
; long delay sub-routine
; (for debugging)
;=============================
long_delay
movlw D'200' ; w = 200 decimal
movwf J ; J = w
jloop: movwf K ; K = w
kloop: decfsz K,f ; K = K-1, skip next if zero
goto kloop
decfsz J,f ; J = J-1, skip next if zero
goto jloop
return

etc...

skimask
- 7th May 2007, 18:10
Below is a program I have with the book I am reading. I am confused with the command to the lcd like ( INITIALIZE LCD PROCEDURE ):
DISPLAY OFF
ENTRY MODE SET
etc..
I know what they do , but they all send 8 bit to the PORTA. How does it know one is for the display and another for the mode entry ? is it an order. it just seem he is sending byte after byte on the same port.
ken


Check the datasheets for any parallel input LCD, they're usually driven by a Hitachi 44780 compatible controller chip.
The pin on the LCD you are probably looking for is the RS pin. In one state, you are accessing the actual memory displayed on the screen, in the other state, you are accessing the control functionality of the LCD controller.

lerameur
- 7th May 2007, 18:57
Ok , he is doing in the program the following:
sending
0 0 1 1 1 0 0 0 to portA
then
0 0 0 0 1 0 0 0 to portA
then
0 0 0 0 0 1 1 0 to portA
then
0 0 0 1 0 1 0 0 to portA

how do we know which one is which (DISPLAY OFF,
ENTRY MODE SET etc...)

k

skimask
- 7th May 2007, 19:05
Ok , he is doing in the program the following:
sending
0 0 1 1 1 0 0 0 to portA
then
0 0 0 0 1 0 0 0 to portA
then
0 0 0 0 0 1 1 0 to portA
then
0 0 0 1 0 1 0 0 to portA

how do we know which one is which (DISPLAY OFF,
ENTRY MODE SET etc...)

k

Get a datasheet for nearly any parallel input LCD (Hitachi 44780 controller chip) and match the bit positions on PortA in the program with the bit positions in the LCD's datasheet. They will match up as long as you have a decent datasheet.

mister_e
- 7th May 2007, 19:12
There's some datasheet with initialisation chart example (http://inst.eecs.berkeley.edu/~cs150/sp05/Lab/Checkpoint3.PDF) . You may try to find some PicBasic LCD routine (not PBP of course)

now it's just a matter of finding the values in the datasheet.

a while back i did something for a 4 bit mode, the initialisation sequence looked like..

' ---------------------------------------------
' LCD Initialisation for HD44780 and compatible
' 4 BIT MODE
' ---------------------------------------------
asm
; LCD_OUT Mode, Data, DelayUS
LCD_OUT ONCE, 30h, 5000 ; I want to use 4 bit mode !
LCD_OUT ONCE, 30h, 500 ; Did you hear me?
LCD_OUT ONCE, 30h, 500 ; Last chance or... too bad!
LCD_OUT ONCE, 20h, 500 ; Official 4 bit mode start

LCD_OUT SPLIT, 28h, 0 ; Function set [4bit, 2lines,5x7]
LCD_OUT SPLIT, 0Ch, 0 ; turn on the display
LCD_OUT SPLIT, 01h, 0 ; clear it
LCD_OUT SPLIT, 06h, 0 ; entry mode
endasm

if you need the source code, i can post it.

lerameur
- 11th May 2007, 16:05
HI, I found the tutorial from Bigonoff for the pic16F84, I read it and it was very good. He also has a tutorial for the pic16F877 (in french also) does anyone has it. Unfortunaetly he removed it from his web site. Have a look
http://www.abcelectronique.com/bigonoff/
I would appreciate if somebody who had this 500 page pdf to sent it to me
thanks

ken

mister_e
- 11th May 2007, 23:02
i knew he was an a s s h o l e but at that point :eek:

anyways, i think i may have a PDF copy of a OLD previous lessons of him.

I think i also have a copy of CEGEP du vieux Montreal lesson somewhere... I'll let you know if i find it.

Acetronics2
- 12th May 2007, 09:17
Hi, Ken

The site is only TEPORARILLY Shut Down ...

The fact is Bigo. didn't appreciate to get a TRUE "State Leader" ( Whether he is Socialist or Capitalist !!! ).

May be he could apply His shiny democracy lessons to himself ...

We just have to wait a moment for him to get out of Childhood ...

Alain

He's not the only " who knows" ( we've got TRENT here ...)

have a look here, in between :

http://www.hobbyprojects.com/microcontroller_tutorials.html

P.S : I DO Have the 5+ Zip files on my HDD ... if really necessary.

mister_e
- 12th May 2007, 09:47
and while we're at it, MikroElektronika also do some kind of tutorial as well
http://www.mikroe.com/en/books/picbook/picbook.htm

untill Mr Bigonoff break his own stupid buble, the above is for sure a nice start point... but as Mr Bigonoff.. it's outdated. Bah, ASM is ASM.

Ruben Pena
- 30th April 2008, 20:22
Dear Julio:
Are you J.A.Sanchez from the Video stamp project in April 08 Circuit Cellar ?. If so..
I have several questions about the project:
I made a small PCB to mount the components, but I added a 4k7 resistor at the Mclr pin,
because I can not find where do you define the use of the internal reset.
It works since the first time,but I found comm errors in the transmited data... I will add
a 8MHZ resonator and will try again...(Note if I cut the Mclr resistor it stops working).
Also... when I programmed the original hex file with the USB Melabs Progremmer,the osc
fuse is configured as extrc. Any comments...?
My congratulations for this outstanding proyect.
PBP 2.5 MPLAB 8.02 PIC18F2520
Greetings...
Ruben de la Pena V.

skimask
- 30th April 2008, 21:27
Dear Julio:
Are you J.A.Sanchez from the Video stamp project in April 08 Circuit Cellar ?....
If you read a bit closer, you'll notice this in the very first post:


hello
Below is a program I have with the book I am reading. I am confused with the command to the lcd like ( INITIALIZE LCD PROCEDURE ):

As far as your config fuse issues, refer to posts #7 and #8 of:
http://www.picbasic.co.uk/forum/showthread.php?t=5777

mvs_sarma
- 1st May 2008, 20:06
hello
Below is a program I have with the book I am reading. I am confused with the command to the lcd like ( INITIALIZE LCD PROCEDURE ):
DISPLAY OFF
ENTRY MODE SET
etc..
......................
ken
.............

the terms quoted by you are after ";" thus not part of program they are only for explanation purpose,