Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pi coding 18f series, assembly code for lcd, help reqd

Status
Not open for further replies.

mgbglasgow

Junior Member level 1
Junior Member level 1
Joined
Jun 15, 2011
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,508
hi all,

my first post, im having issues with lcd on pic 18f1320, have ported the code from 16f84 sample and can place the cursor on the lcd with ease, but just cant get a character to appear.

my code is below, any help would be greatly appreciated

; lcd routine, testing delay routines for 5ms (4.1ms), 50ms (40ms), 150us (100us mini.)

;*********************************************************
INCLUDE "P18F1320.INC"
; EQUATES SECTION





;*********************************************************

LIST P=PIC18F1320, ; we are using the 18F1320
ORG 0 ;the start address in memory is 0
GOTO START ; goto start!

;**********************************************************************
; Configuration Bits


CONFIG IESO=OFF ;disable osc switching
CONFIG BORV=45 ;set brown out to 4.5 volts
CONFIG PWRT=ON ;use power timer
CONFIG BOR=ON ;enable brown out protection
CONFIG WDT=OFF ;diasble WDT


;*********************************************************
;SUBROUTINE SECTION.





; 100ms SECOND DELAY, VALUE OF FFC2


DELAYP1 MOVLW 0x08
MOVWF T0CON
MOVLW 0xFF
MOVWF TMR0H
MOVLW 0xC2
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON, TMR0ON
AGAIN5 BTFSS INTCON, TMR0IF
BRA AGAIN5
BCF T0CON, TMR0ON
RETLW 0

; 250ms SECOND DELAY, VALUE OF FFC2


DELAYP25 MOVLW 0x08
MOVWF T0CON
MOVLW 0xFF
MOVWF TMR0H
MOVLW 0x5A
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON, TMR0ON
AGAIN3 BTFSS INTCON, TMR0IF
BRA AGAIN3
BCF T0CON, TMR0ON
RETLW 0


; 1 SECOND DELAY, VALUE OF E0FF


DELAY1 MOVLW 0x08
MOVWF T0CON
MOVLW 0xE0
MOVWF TMR0H
MOVLW 0xFF
MOVWF TMR0L
BCF INTCON, TMR0IF
BSF T0CON, TMR0ON
AGAIN4 BTFSS INTCON, TMR0IF
BRA AGAIN4
BCF T0CON, TMR0ON
RETLW 0

CLOCK BSF PORTA,2 ;Clock RB0 high
CALL DELAYP25
BCF PORTA,2 ;Clock RB0 low.
CALL DELAYP25
RETLW 0



DELAY3 CALL DELAY1 ;3 second delay
CALL DELAY1
CALL DELAY1
RETLW 0


;*********************************************************
Aa MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 1H ;41 is code for A
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Bb MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 2H ;42 is code for B
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Cc MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 3H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Dd MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 4H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Ee MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 5H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Ff MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 6H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Gg MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 7H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Hh MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 8H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Ii MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 9H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Jj MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 0AH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Kk MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 0BH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Ll MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 0CH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Mm MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 0DH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Nn MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
MOVLW 0EH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Oo MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVLW 0FH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Pp MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 0H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Qq MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 1H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0


Rr MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 2H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Ss MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 3H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Tt MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 4H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Uu MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 5H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Vv MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 6H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0


Ww MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 7H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Xx MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 8H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0


Yy MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 9H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

Zz MOVLW 2
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVLW 0AH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM0 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 0H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM1 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 1H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM2 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 2H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM3 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 3H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM4 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
MOVLW 4H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM5 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 5H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM6 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 6H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM7 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 7H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM8 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 8H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

NUM9 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVLW 9H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

GAP MOVLW 2
MOVWF PORTA
MOVLW 2H
MOVWF PORTB
CALL CLOCK
MOVLW 0H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0


DOT MOVLW 2
MOVWF PORTA
MOVLW 2H
MOVWF PORTB
CALL CLOCK
MOVLW 0EH
MOVWF PORTB
CALL CLOCK ;clock character onto display.
RETLW 0

CLRDISP CLRF PORTA
MOVLW 0H
MOVWF PORTB
CALL CLOCK ;clock character onto display.
MOVLW 1
MOVWF PORTB
CALL CLOCK
CALL DELAYP1
RETLW 0




;*********************************************************

;CONFIGURATION SECTION

START BSF STATUS,5 ;Turns to Bank1.

MOVLW B'00000000' ;All 5bits of PORTA are all outputs
MOVWF TRISA

MOVLW B'00000000'
MOVWF TRISB ;PORTB is OUTPUT



BCF STATUS, 5


CLRF PORTA ;Clears PortA.
CLRF PORTB ;Clears PortB.

;Display Configuration

MOVLW 03H ;FUNCTION SET
MOVWF PORTB ;8bit data (default)
CALL CLOCK

CALL DELAYP1 ;wait for display
MOVLW 02H ;FUNCTION SET
MOVWF PORTB ;change to 4bit
CALL CLOCK ;clock in data

CALL DELAYP1 ;wait for display
MOVLW 02H ;FUNCTION SET
MOVWF PORTB ;must repeat command
CALL CLOCK ;clock in data

CALL DELAYP1 ;wait for display
MOVLW 08H ;4 bit micro
MOVWF PORTB ;using 2 line display.
CALL CLOCK ;clock in data

CALL DELAYP1
MOVLW 0H ;Display on, cursor blinking
MOVWF PORTB ;0EH
CALL CLOCK
MOVLW 0FH
MOVWF PORTB
CALL CLOCK
CALL DELAY3

CALL DELAYP25
MOVLW 0H ;Increment cursor, 06H
MOVWF PORTB
CALL CLOCK
MOVLW 6H
MOVWF PORTB
CALL CLOCK


;*********************************************************
;Program starts now.

BEGIN CALL CLRDISP


CLRF PORTA
MOVLW 8H ;Cursor at MID TOP, 88H
MOVWF PORTB
CALL CLOCK
MOVLW 0H
MOVWF PORTB
CALL CLOCK

LOOP CALL Aa
CALL DELAY1
CALL Bb
CALL DELAY1
CALL Cc
CALL DELAY1
GOTO LOOP





















END
 

seems to be that the ports are clearing when im using the bit change functions bcf/bsf, my two signals rs and en, are required to communicate with the lcd module, but when i change ra1 to a high/low, it is clearing ra2. as i understand it, this shouldnt happen.

any one seen this?

my work around is to and the reqd figur and send it to the port of course, but all the literture says this should work

puzzled in glasgow...
 

Code:
CLOCK	BSF	 PORTA,2	;Clock RB0 high
CALL	DELAYP25
BCF	 PORTA,2	;Clock RB0 low

Change PORTA to LATA for all instructions that write to a single PORT bit.

Always write to LAT and read from PORT.

For the full explanation, google "Read Modify Write" or R-M-W

Hope this helps
 
thanks hexreader,

will try that, read briefly about lat versus portx yesterday, have code from certain books, and i doubt wether the sample code has ever actually worked.

got my code working yesterday the long way, ie writing words to the port, but i will swat up on rmw .

thanks for the help, much appreciated.
 

Hi,

Have used an assembler 18F 16x2 lcd routine for a long time - there are many slightly different ways doing the same thing.

If you can wait till tonight I can strip it out of my code and produce a complete, tested working program and send it over.

Are you wantng to use a 6 bit o 7 bit version ?
 
hi wp100,, not sure what bit difference is you speak of, im using 18f1320, with pickit 3, on picdemo board 4, but my own lcd 2x16 on port a, rs en, and port b d4567 as data.

all code greatly appreciated as i want to keep on assembly at this point, and next stage is to connect to lm75 using bit bang routine, tried it last week and i know now that the routine wouldnt have worked because of the issues with BCF BSF overwriting the port data.

ps does anyone know how ii can get my code off the pic, and back up onto screen in MPlabm, i read chip, but nowt appears to happen, ?
i forgot to save my script and the pc has updated and rebooted this morning. doh
steve
 

Hi,

Will get some lcd code together for you this evening - what frequency oscillator /crystal are you using - 4 meg ?

Think this should work to read in your program code and dissassemble it -

In MPLAB IDE do:
Programmer\Read (to read the part into memory)
View\3 Program Memory (to view Program Memory)
then and you have a choice of viewing Opcode Hex, Machine and Symbolic, pick Machine or Symbolic (as you have no symbols, they are the same).
Right-click on the Program Memory window and choose from the pop-up menu Output to file

While it will be possible to bit bang that lm75, you will find most other 18F chips do have i2c function built in.
As a beginner a bit banging routine can be a daunting task, you might find it easier to use the LM35 instead.
 

Hi,

Have got some 6 bit lcd code working. Had it running ok on my 18f4520 hardware and on a 1320 in a simulator.

In both all the lcd lines were on PortB, if the RS and E lines are transfered to PortA it does not display correctly - not sure why and just do not have the time to debug it at the moment.
However sure you can easily use it as all PortB pins.

You will see how it uses 32 btyes of ram to hold the data messages with while seeming a long way to do things it does make changing /adding to a message very easy as you can see in the display example.

Let us know if it works ok for you.


Edit / PS ensure the RW pin of the LCD is tied to 0v, otherwise it will not work
 

Attachments

  • 6bitlcdGlasgow.rar
    3.3 KB · Views: 98

thanks for the assist.

been an engineer on electromechanical stuff for years, but my roots are in electronic and electrical engineering (HND), so used to throwing about ones and zeros. its in my blood, been in sales for years, but walked away and back in on it, repairing all sorts as i go with a new job in fife, welders, IPTV, and even on placement fixing missile systems and IPTV solutions now. But really like making stuff too!

have rigged up lm 75 on picdem4 board, and will start to do code tomorow. Ive been running the board on LP oscillator to this point, no fast coding, and delays are all easy, but will be stepping up soon, looked at timing diagrams of lm75 today, and it only states minimums, so will endevaour with 32khz clock presently.

what you working on?

steve
 

Hi,

Have never actually run anything on i2c, have used spi etc.
That sensor has quiet a wide tolerance +-2 C , if thats acceptable to your needs.
Have used the SHT11 range of sensors, but that has to be used with a custom written bit bang code in assembler, though accurate they are expensive.
The DS18B20 sensor is probalby the best in terms of accuracy / cost, though codable in assembler it can be difficult.

You might find these links of help, though don't think you it will work at 32khz, easy enough to use the 8 or 4 meg int osc.
http://ww1.microchip.com/downloads/en/devicedoc/i2c.pdf

**broken link removed**

Did you get the lcd code to work ?
 

hi, lcd working great now, 2x 16 blue unit, very nice to view,

will read through that i2c doc this morning before i do anything,

cheers
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top