Girishs449
Newbie level 5
Hi, I'm new in pic microcontroller. can any one help me in this. i'm doing a program to display "welcome" in an LCD using pic16f877A. i've done it in proteus simulation and its working well. now i'm using a pic16f877 development board. i programmed the controller through pickit2. but its not working.
i'm using MPLAB ASM.
pic 16f877A.
is any error in my program?
can any one help please.
i've attached the simulation screenshot and the code. please help
i'm using MPLAB ASM.
pic 16f877A.
is any error in my program?
can any one help please.
i've attached the simulation screenshot and the code. please help
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 TITLE "LCD4.ASM" ; WORKING WITH AN LCD IN THE 4-BIT MODE LIST P=16F877A, R=DEC INCLUDE "P16F877A.INC" ; DATA SEGMENT CBLOCK 0X00C DEL, CMD ; VARIABLES FOR PASSING THE PARAMETERS TEMP, I ; LOCAL VARIABLES ENDC ; CODE SEGMENT PAGE __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF ORG 0 ; START PROGRAM AT THE BEGINNING OF MEM GOTO START MSG0 ADDWF PCL, F DT" ***WELCOME***", 0 START BSF STATUS, RP0 MOVLW 0X00 MOVWF TRISB ^ 0X80 MOVLW 0X7F MOVWF OPTION_REG ^ 0X80 BCF STATUS, RP0 CALL INITLCD CLRF I L1 MOVF I, W CALL MSG0 IORLW 0 BTFSC STATUS, Z GOTO L2 CALL WRITEDATA INCF I, F GOTO L1 L2 GOTO L2 ; ENDLESS LOOP INITLCD MOVLW 15 MOVWF DEL CALL DELAY ; A 15 MSEC DELAY AFTER POWER IS ON MOVLW 3 MOVWF PORTB ; START LCD INIT PROCESS MOVLW 5 MOVWF DEL CALL DELAY ; WAIT FOR 5 MSEC MOVLW 3 MOVWF PORTB ; START LCD INIT PROCESS BSF PORTB, 4 ; TOGGLE THE LCD ENABLE PIN BCF PORTB, 4 MOVLW 5 MOVWF DEL CALL DELAY ; WAIT FOR 5 MSEC BSF PORTB, 4 ; REPEAT THE RESET COMMAND (2ND TIME) BCF PORTB, 4 MOVLW 40 ; WAIT FOR 200 USEC SUBLW 1 SUBLW 0 BTFSS STATUS, Z GOTO $-3 BSF PORTB, 4 ; REPEAT THE RESET COMMAND (3RD TIME) BCF PORTB, 4 MOVLW 40 ; WAIT FOR 200 USEC SUBLW 1 SUBLW 0 BTFSS STATUS, Z GOTO $-3 MOVLW 2 ; INITIALIZE LCD 4-BIT MODE MOVWF PORTB BSF PORTB, 4 ; TOGGLE THE LCD ENABLE PIN BCF PORTB, 4 MOVLW 0X28 ; 2-LINE MODE CALL WRITECMD MOVLW 1 CALL WRITECMD ; CLEAR DISPLAY MOVLW 5 ; WAIT FOR 5 MSEC AFTER CLEARING MOVWF DEL CALL DELAY MOVLW 0X06 ; CURSOR MOVE AFTER EACH CHAR CALL WRITECMD MOVLW 0X0C ; TURN ON LCD AND ENABLE CURSOR CALL WRITECMD RETURN WRITECMD ; WRITE TO LCD A 1-BYTE COMMAND IN W MOVWF TEMP SWAPF TEMP, W ANDLW 0X0F ; LEAVE ONLY THE HIGH 4 BITS IN W MOVWF PORTB BSF PORTB, 4 ; TOGGLE THE E BIT BCF PORTB, 4 MOVFW TEMP ; PROCEED WITH THE LOW BIT ANDLW 0X0F MOVWF PORTB BSF PORTB, 4 ; TOGGLE THE BIT BCF PORTB, 4 MOVLW 40 ; WAIT FOR 200 USEC SUBLW 1 SUBLW 0 BTFSS STATUS, Z GOTO $-3 RETURN WRITEDATA ; WRITE TO LCD A 1-BYTE DATA IN W MOVWF TEMP SWAPF TEMP, W ANDLW 0X0F ; LEAVE ONLY THE LOWER 4 BITS IN W MOVWF PORTB BSF PORTB, 5 ; SENDING DATA BSF PORTB, 4 ; TOGGLE THE E BIT BCF PORTB, 4 MOVFW TEMP ; PROCEED WITH THE LOW BIT ANDLW 0X0F MOVWF PORTB BSF PORTB, 5 ; SENDING DATA BSF PORTB, 4 ; TOGGLE THE BIT BCF PORTB, 4 MOVLW 5 ; WAIT FOR 5 MSEC MOVWF DEL CALL DELAY RETURN DELAY MOVLW 200 SUBLW 1 ; THIS LOOP TAKES 5US*200 = 1MS SUBLW 0 BTFSS STATUS, Z GOTO $-3 DECFSZ DEL,F GOTO DELAY RETURN END
Last edited by a moderator: