1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics LCD controlled by microcontroller

Discussion in 'Modding' started by eaterofpies, 26 Jan 2004.

  1. eaterofpies

    eaterofpies What's a Dremel?

    Joined:
    12 Feb 2002
    Posts:
    1,745
    Likes Received:
    0
    ive had the code ready to test for a while and i finally got off my back side and did it today (instead of revision)

    [​IMG]

    the program is for a p89c66x microcontroller which is based on an 80c51 (tested on p89c664). it is written in assembly (used Raisonance IDE) and it controls a standard 20x4 parallel lcd. This is the first part of my current project which isnt a serial backpack but it wouldnt be too hard to use the code or convert the code for different sized lcds.

    sorry if the code isnt too easy to read / understand but im new to this assembler stuff and its only my 3rd program including the LED flashing one everyone does.



    Code:
     $DEBUG	
    $include	(reg66x.inc)
    ;/////////////////////////////////////////////
    ;Start Date		:10/01/2004
    ;Author			:Stephen Lynch (A.K.A. Eaterofpies)
    ;
    ;register uses
    ;r0 = lcd line out char number
    ;r1 = lcd line out line number
    ;r2 = fan pass number
    ;r6 = delay loop var
    ;r7 = delay loop var
    
    ;Port / Pin usage
    ;----------------
    ;port 2: d0-d7 on parallel LCD
    ;port 3: pins 5-7: RS, RW, E on LCD
    lcddata equ p2
    RS equ p3.5
    RW equ p3.6
    E equ p3.7
    
    			org 0
    			sjmp START
    			org 40
    		
    START:	acall GENERAL 		;general initialisation
    	acall INITLCD	;Initialise LCD + write test data
    	End
    			
    general:  mov p0, #0
    	mov p1, #0
    	mov p2, #0
    	mov p3, #0 ;all data pins clear
    	ret
    						
    initlcd:    acall ldelay		;delay 20 ms
    	acall ldelay
    	acall ldelay
    	acall ldelay
    	mov lcddata, #48	;initialise lcd
    	acall Do_E			
    	acall ldelay		;delay 5 ms 
    	mov lcddata, #48	;and again
    	acall Do_E					
    	acall ldelay		;delay 160us or more
    	mov lcddata, #48 	;and again
    	acall Do_E
    	acall sdelay		;delay 160us again
    	mov lcddata, #56 	;set multiline and 8 bit
    	acall Do_E
    	mov lcddata, #8	;display off :-/
    	acall Do_E
    			
    	mov lcddata, #1	;clear lcd
    	acall Do_E
    			
    	mov lcddata, #6  	;write L->r not s/d
    	acall Do_E
    			
    	acall ldelay		;wait 5ms
    			                  
    	mov lcddata, #12 	;display on :)
    	acall Do_E
    									
    	 ;//////////////
    	 ;lcd is initialised now write to all 4 lines as a test
    	 ;//////////////
    			                  
    	acall ldelay	;wait 5 ms
    
    	mov dptr, #initmsglcd1	;dptr = lines 1st char
    	mov R1, #1		;set output line to 1
    	acall lcdlineout			;output line
    
    	acall sdelay
    	mov dptr, #initmsglcd2	;dptr = lines 1st char
    	mov R1, #2		;set output line to 2
    	acall lcdlineout			;output line
    
    	acall sdelay
    	mov dptr, #initmsglcd3	;dptr = lines 1st char
    	mov R1, #3		;set output line to 3
    	acall lcdlineout		;output line
    
    	acall sdelay
    	mov dptr, #initmsglcd4	;dptr = lines 1st char
    	mov R1, #4		;set output line to 4
    	acall lcdlineout		;output line
    	acall sdelay
    	ret
    
     
    
    lcdlineout: djnz R1, notLine1 	;skip 2 lines if not line 1
    	mov lcddata, #128		;start address = 128+1
    	sjmp linesetret		;go to rest of line out
    notline1: djnz R1, notLine2		;skip 2 lines if not 2
    	mov lcddata, #128 + 41
    	sjmp linesetret
    notline2: djnz R1, notLine3		;skip 2 lines if not 3
    	mov lcddata, #128 + 20
    	sjmp linesetret
    notline3: mov lcddata, #128 + 84 ;must be line 4
    	sjmp linesetret
    
    linesetret:acall do_e
    	acall sdelay
    	setb RS			;send char not control
    	mov r0, #20		;set line length
    lcdloop:	clr a			;clear accumulator
    	movc a, @a+dptr		;moves character to acc
    	mov lcddata, a		;sets p2 to chars code
    	inc dptr			;set dprt to next char
    	acall Do_E		;strobe the char out
    	acall sdelay		;delay of 160 us
    	djnz r0, lcdloop		;loop for the length of line
    	clr RS			;go back to control mode
    	ret
    
    Do_E:	setb E  			;strobes E to tell display that
    	clr E			;there is work to be done
    	ret
    ;/////////////////
    ;200us delay
    ;/////////////////
    sdelay:	mov r7, #92
    sdelayl:	nop;1/2 a us
    	nop;
             	djnz r7, sdelayl
             	ret         
    
    ;///////////////////
    ;5ms delay
    ;///////////////////        
    ldelay:	mov r6, #10
    ldelayo:	mov r7,#234
    ldelayi:	nop
    	nop
    	djnz r7, ldelayi
    	djnz r6, ldelayo
    	ret
    ;/////////////////////////////
    ;text outputs
    ;/////////////////////////////
    ;init messages
    initmsglcd0:db "\\Initialising lcd//"
    initmsglcd1:db "\\\Testing Line 1///"
    initmsglcd2:db "\\\Testing Line 2///"
    initmsglcd3:db "\\\Testing Line 3///"
    initmsglcd4:db "\\\Testing Line 4///"
    
    feel free to use this code for whatever you want or if anyone wants any help controlling lcds with micros feel free to ask
     
  2. computer

    computer What's a Dremel?

    Joined:
    10 Jan 2004
    Posts:
    205
    Likes Received:
    0
    how hard is it to make a little graph on an LCD which will get longer (more vertical bars) as the voltage to a pin goes from 0v (no bars) to 10v (full line)?

    impossible or very hard :D?
     
  3. eaterofpies

    eaterofpies What's a Dremel?

    Joined:
    12 Feb 2002
    Posts:
    1,745
    Likes Received:
    0
    which voltage pin? and not too hard if u have a way of getting the data into the microcontroller. an ADC would be easy to use to get the data in especially if it was a serial one. if you need accracy tho a numerical display will be better than a bar graph.
     
  4. computer

    computer What's a Dremel?

    Joined:
    10 Jan 2004
    Posts:
    205
    Likes Received:
    0
    yea read my post about 8 channel light controller about an LCD

    I was thinking if I find a chip which will accept 8 analouge inputs one for each matrix then a 4x16 or 2x16 display would allow nice numbers and text along with bar graphs selectable by mode buttons or something... perhaps make a post in my other thread if you have any more details to keep my project details together...
     
  5. Ardentfrost

    Ardentfrost What's a Dremel?

    Joined:
    22 Jan 2004
    Posts:
    292
    Likes Received:
    1
    that is a very easy program Computer. You can easily make a character for a unit of the LCD, then, you only need 8 or so different characters... one that lights the bottom line, one that light the bottom two, .... , one that lights them all. Then, you pass the voltage into an ADC and take the output into your pic (or other MCU). Then, you adjust the number so that it ranges from 0 - xxx and you print out the characters need accordingly.

    So, let's say you wanna go to 8 V and each unit has 8 rows. Each volt will light up 1 row (if the LCD matrix is 1xX). I probably have some test code that will do that somewhere around here (probably in my old MCU text book) and if you'd like for me to dig it up and type it out, just ask :)

    Regards

    PS, you guys made 2 posts while I was typing this up, I need to get quicker or make smaller posts ;)
     

Share This Page