Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 ;processor: PIC 16F84 ;assembler: MPASM.EXE by MicrochiP ;modules used: pp-bus, pp-ctr, pp-key, pp-lcd ;---------------------------------------------------------------------------- processor 16f84 ;Processor type... org 2007 ;fuse settings: de b'11001' ;CP=off, PWRTE=enable; WDT=disable. ;bit1,0: 11 =RC-Oscillator ; 01 =XT-Oscillator ;---------------------------------------------------------------------------- w equ 00 ;Working-Register address f equ 01 ;File-Register address Z equ 02 ;Zero-Bit porta equ 05 ;RB port portb equ 06 ;RB port trisa equ 85 ;TRISA Register trisb equ 86 ;TRISB Register status equ 03 ;Status Register RP0 equ 05 ;Status Reg. Bit 5 pcl equ 02 ;Program Counter Low _switch1 equ 00 ;switch1, input RA0 _switch2 equ 01 ;switch2, input RA1 _LCD_E equ 02 ;LCD-Enable, RA2 _LCD_RS equ 03 ;LCD register select, RA3 _time0_1 equ 0c ;Register for time loop 0,1ms _time4ms equ 0d ;Register for time loop 4ms _nrchrs equ 0e ;character counter ;---------------------------------------------------------------------------- org 00 ;Reset vector goto _main ;Program Start address ;------------------------ Initialise ports------------------------- _portinit clrf porta ;porta = 0 clrf portb ;portb = 0 bsf status,RP0 ;select Bank 1 movlw b'00011' ;write b'00000010' to W-Register movwf trisa ;RA0/1 are inputs clrf trisb ;trisb = 0000 0000 (output) bcf status,RP0 ;select Bank 0 return ;end subroutine ;-------------------- Initialise LC-Display ----------------------- _lcdinit bcf porta,_LCD_RS ;RS-Bit low movlw b'00110000' ;LCD Initialise call _w2lcd ; call _4ms ;wait _4ms movlw b'00110000' ;LCD Initialise call _w2lcd ; movlw b'00110000' ;LCD Initialise call _w2lcd ;jump to UP _w2lcd movlw b'00111000' ;Function Set ;db4=1 > 8 bit data ;db3=1 > Display 2 lines ;db2=0 > 5*8dots call _w2lcd ; movlw b'00001110' ;Display Control ;db2=1 > display on ;db1=1 > cursor on ;db0=0 > cursor doesn't blink call _w2lcd ; movlw b'00000001' ;clear display call _w2lcd ; return ;end subroutine ;---------------- write content of w to lcd ------------------ _w2lcd movwf portb ;copy W-Reg. to portb bsf porta,_LCD_E ;toggle enable bcf porta,_LCD_E ;toggle enable clrf portb ;portb = 0 ; Time loop, approx. 100 mys (delay for LCD) _100mys movlw d'25' ;d'25' in W-Register movwf _time0_1 ;copy W to register _time0_1 __m1 decf _time0_1,f ;decrement Reg. _time0_1 btfss status,Z ;if Zero Bit in Status Register = 1 ;skip next instruction goto __m1 ;jump to __m1 return ;end subroutine ; Time loop approx. 4 ms (delay for LCD) -- _4ms movlw d'40' ;d'40' in W-Register movwf _time4ms ;copy W to _time4ms __m2 call _100mys ; delay 100mys decf _time4ms,f ;decrement _time4ms btfss status,Z ;if Zero Bit in Status Register = 1 ;skip next instruction goto __m2 ;jump to __m2 return ;end subroutine ;------------- move LCD-Cursor to first line, leftmost position -------------- _lcdline1 movlw b'10000000' ;b'10000000' in W-Register movwf portb ;copy W-Reg. to portb call _w2lcd ;jump to _w2lcd return ;end subroutine ;------------- move LCD-Cursor to second line, leftmost position -------------- _lcdline2 movlw b'11000000' ;b'11000000' in W-Register movwf portb ;copy W to portb call _w2lcd ;write to LCD return ;end subroutine ;-------------- output text to LCD ---------------- _txt2lcd bsf porta,_LCD_RS ;switch to LCD Data Mode __m3 movf _nrchrs,w ;copy _nrchrs to W-Register call _text ;write last character iorlw 0 ; btfsc status,Z ;if Zero Bit in Status Register = 0 ;skip next instruction goto __m4 ;jump to __m4 call _w2lcd ;jump to _w2lcd incf _nrchrs,f ;increment _nrchrs goto __m3 ;jump to __m3 __m4 bcf porta,_LCD_RS ;reset RS-Bit return ;end subroutine ;------------------ reads next character into W-Register ------------------ _text addwf pcl,f ;Add Prog.Counter Low to W-Reg. den ;result in f dt "Hello ",0 ;Text1 (define table) dt "World...........",0 ;Text2 (Assembler directive) ;**************************** Main program ********************************* _main call _portinit ;initialise ports call _lcdinit ;lcd init __m5 btfss porta,_switch2 ;if switch2 porta = 1 ;skip next instruction goto __m5 ;jump to __m5 clrf _nrchrs ;clear File_Register _counter ;(=start Text1) call _txt2lcd ;send text to LCD __m6 btfsc porta,_switch2 ;if switch2 porta = 0 ;skip next instruction goto __m6 ;jump to __m6 call _lcdline2 ;get second line movlw d'17' ;d'17' in W-Register movwf _nrchrs ;W to Register _nrchrs (=start Text2) call _txt2lcd ;write second line __m7 btfss porta,_switch1 ;if switch1 porta = 1 ;skip next instruction goto __m7 ;jump to __m7 movlw b'00000001' ;clear display call _w2lcd ; goto __m5 ;_ end ;end program ;********************************** END ************************************
[B]REMOVE THIS CODE[/B]
[I] ; processor: PIC 16F84
;assembler: MPASM.EXE by MicrochiP
;modules used: pp-bus, pp-ctr, pp-key, pp-lcd
;----------------------------------------------------------------------------
; processor 16f84 ;Processor type...
; org 2007 ;fuse settings:
; de b'11001' ;CP=off, PWRTE=enable; WDT=disable.
; bit1,0: 11 =RC-Oscillator
; 01 =XT-Oscillator[/I]
[B][I]ADD THIS CODE[/I][/B]
[B] list p=16F84 ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
[/B]
;----------------------------------------------------------------------------
However when I tried your code it seems to simulate ok at 4mhz, if you run the lcd program 5 times faster with the 20mhz crystal it will almost certainly fail.
Thanks a lot sir..it worked this time...actually, it has to..
Sir as you have modified the code for lcd initialisation and its delay routine corresponding to 20mhz crystal...can't it be driven on 4 mhz itself. the code which i gave you was written for 4mhz only, then why it didnt work for 4 mhz? it was simulated, and displayed the required result on simulation, then why not on h/w?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?