1. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    Im quite new to Microcontrollers, and I need some help getting the LCD display system working for PIC16f887, 2x16 display system, using MPlab IDE v8.10. The code that I have at the moment is:

    Code ( (Unknown Language)):
    1.  
    2. LIST p = 16F887 ;Simply sets the processor type being used
    3. #INCLUDE <P16F887.INC> ;file for processor, adds predifined labels
    4.  
    5. __CONFIG _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _LVP_OFF
    6. ; Sets many parameters
    7. org 0x00 ; Start the code at location zero
    8.  
    9.  
    10. LCD_PORT Equ PORTB
    11.  
    12. LCD_TRIS Equ TRISB
    13. LCD_RS Equ 0x04 ;LCD handshake lines
    14. LCD_E Equ 0x05
    15.  
    16.  
    17. CBLOCK 0x20
    18. count ; Counter used when switch pressed has stopped
    19. count1 ; 160us Counter variable
    20. counta ; variables for delay timers
    21. countb ; variables for delay timers
    22. LCDTemp ; 4 bit for LCD
    23. ENDC ;
    24.  
    25. org 0x000 ;
    26. goto Init ;
    27.  
    28. HEX_Table
    29. addwf PCL, f
    30. retlw 0x30
    31. retlw 0x31
    32. retlw 0x32
    33. retlw 0x33
    34. retlw 0x34
    35. retlw 0x35
    36. retlw 0x36
    37. retlw 0x37
    38. retlw 0x38
    39. retlw 0x39
    40. retlw 0x41
    41. retlw 0x42
    42. retlw 0x43
    43. retlw 0x44
    44. retlw 0x45
    45. retlw 0x46
    46.  
    47. Text
    48. addwf PCL, f
    49. retlw 'W'
    50. retlw 'A'
    51. retlw 'M'
    52. retlw 'B'
    53. retlw 'U'
    54. retlw 'L'
    55. retlw 'U'
    56. retlw 'L'
    57. retlw 'U'
    58. retlw ' '
    59. retlw ' '
    60. retlw ' '
    61. retlw 0x00
    62.  
    63. Text2
    64. addwf PCL, f
    65. retlw 'B'
    66. retlw 'D'
    67. retlw 'N'
    68. retlw 'S'
    69. retlw 'O'
    70. retlw 'N'
    71. retlw ' '
    72. retlw ' '
    73. retlw ' '
    74.  
    75.  
    76.  
    77. retlw 0x00
    78.  
    79. ; Initialize the PIC and the LCD
    80. Init ;
    81. bsf STATUS,5 ;set memory bank 3
    82. bsf STATUS,6
    83. clrf ANSEL ;cofigure pins as digital
    84. clrf ANSELH
    85.  
    86. bcf STATUS,5 ;set memory bank 2
    87. bcf CM1CON0,7 ;disable comparators
    88. bcf CM2CON1,7
    89.  
    90. bcf STATUS,6 ;set memory bank 1
    91. bsf STATUS,5
    92. movlw 0XC0
    93. movwf TRISA ;set port A as output except output 6 and 7
    94. clrf TRISB ;set port B as output
    95. clrf TRISC ;set port C as output
    96. clrf TRISD ;set port D as output
    97. bcf STATUS,5 ;set memory bank 0
    98.  
    99.  
    100. call LCDInit ; Initialize the LCD Display
    101.  
    102.  
    103. ; Main program...
    104. Message
    105. movf count, w ; put counter value in W
    106. goto NextMessage ; display next message if finished
    107. xorlw 0x00 ; is it a zero?
    108. btfsc STATUS, Z
    109. call text; get a character from the text table
    110. call LCD_Char
    111. incf count, f
    112. goto Message
    113.  
    114. NextMessage
    115. call LCD_L2 ;move to 2nd row, first column
    116. clrf count ;set counter register to zero
    117.  
    118. Message2
    119. movf count, w ;put counter value in W
    120. call Text2 ;get a character from the text table
    121. xorlw 0x00 ;is it a zero?
    122. btfsc STATUS, Z
    123. goto EndMessage
    124. call LCD_Char
    125. incf count, f
    126. goto Message2
    127.  
    128. EndMessage
    129.  
    130. ; Infinate loop
    131. Stop
    132. goto Stop ;endless loop
    133.  
    134. ; LCD routines and subs
    135. LCDInit ; 4 Bit Initialization...
    136. call Del05 ; Wait 15 msecs
    137. call Del05 ;
    138. call Del05 ;
    139. movlw 0x03 ; Send the Reset Instruction
    140. movwf LCD_PORT ;
    141. call Pulse_e ; Pulse LCD_E
    142. call Del05 ; Delay 5ms
    143. call Pulse_e ; Pulse LCD_E
    144. call D160us ; Delay of 160us
    145. call Pulse_e ; Pulse LCD_E
    146. call D160us ; Delay of 160us
    147. movlw 0x02 ; Send the Data Length Specification
    148. movwf LCD_PORT ;
    149. call Pulse_e ; Pulse LCD_E
    150. call D160us ; Delay of 160us
    151. movlw 0x028 ; Set Interface Length
    152. call LCDIns ;
    153. movlw 0x010 ; Turn Off Display
    154. call LCDIns ;
    155. movlw 0x001 ; Clear Display RAM
    156. call LCDIns ;
    157. movlw 0x006 ; Set Cursor Movement
    158. call LCDIns ;
    159. movlw 0x00C ; Turn on Display/Cursor
    160. call LCDIns ;
    161. call LCD_Clr ; Clear the LCD
    162. return ;
    163.  
    164. LCDIns ; Send the Instruction to the LCD
    165. movwf LCDTemp ; Save the Value
    166. swapf LCDTemp, 1
    167. movf LCDTemp, 0
    168. andlw 0x0F ; Most Significant Nibble first
    169. movwf LCD_PORT ;
    170. bcf LCD_PORT, LCD_RS ;
    171. call Pulse_e ;
    172. swapf LCDTemp, w ; Least Significant Nibble Second
    173. andlw 0x0F ;
    174. movwf LCD_PORT ;
    175. bcf LCD_PORT, LCD_RS ;
    176. call Pulse_e ;
    177. call Del01 ; wait 1 ms
    178. movf LCDTemp, w ;
    179. andlw 0xFC ; Have to Delay 5 msecs?
    180. btfsc STATUS, Z ;
    181. call Del01 ; 1ms
    182. return ;
    183.  
    184. LCD_CharD
    185. addlw 0x30 ; add 0x30 to convert to ASCII
    186. LCD_Char ; Send the Character to the LCD
    187. movwf LCDTemp ; Save the Value
    188. swapf LCDTemp, 1
    189. MovF LCDTemp, 0
    190. andlw 0x0F ; Most Significant Nibble first
    191. movwf LCD_PORT ;
    192. bsf LCD_PORT, LCD_RS ;
    193. call Pulse_e ;
    194. swapf LCDTemp, w ; Least Significant Nibble Second
    195. andlw 0x0F ;
    196. movwf LCD_PORT ;
    197. bsf LCD_PORT, LCD_RS ;
    198. call Pulse_e ;
    199. call Del05 ;
    200. nop ;
    201. return ;
    202.  
    203.  
    204. LCD_L2: movlw 0xc0 ; move to 2nd row, first column
    205. call LCDIns ;
    206. retlw 0x00 ;
    207.  
    208. LCD_Clr movlw 0x01 ; Clear display
    209. call LCDIns ;
    210. retlw 0x00 ;
    211.  
    212. Pulse_e ;
    213. bsf LCD_PORT, LCD_E ; LCD Enable pulse to write data from PORTB
    214. nop ; into LCD module.
    215. nop
    216. bcf LCD_PORT, LCD_E ;
    217. nop ;
    218. nop
    219. retlw 0x00 ;
    220.  
    221.  
    222. ; Delay routines...
    223. D160us
    224. clrf count1 ;
    225. bsf count1, 5 ; Delay 160 usecs
    226. bsf count1, 4 ;
    227. decfsz count1, f ;
    228. goto $ - 1 ;
    229. return ;
    230.  
    231. Del255 movlw 0xff ; delay 255 mS
    232. goto d0 ;
    233. Del200 movlw d'255' ; delay 200mS
    234. goto d0 ;
    235. Del100 movlw d'200' ; delay 100mS
    236. goto d0 ;
    237. Del50 movlw d'100' ; delay 50mS
    238. goto d0 ;
    239. Del20 movlw d'40' ; delay 20mS
    240. goto d0 ;
    241. Del05 movlw 0x10 ; delay 5.000 ms (4 MHz clock)
    242. goto d0 ;
    243. Del01 movlw 0x05 ; delay 1.000 ms (4 MHz clock)
    244. d0 movwf count1 ;
    245. d1 movlw 0xC7 ; delay 1mS
    246. movwf counta ;
    247. movlw 0x04 ;
    248. movwf countb ;
    249. Del_0 decfsz counta,f ;
    250. goto $+2 ;
    251. decfsz countb,f ;
    252. goto Del_0 ;
    253. decfsz count1,f ;
    254. goto d1 ;
    255. retlw 0x00 ;
    256.  
    257. end
    258. ----------------------------------------------------------------------
    259. Debug build of project `C:\Users\samuel\Desktop\comp245\lab2\lab2.mcp' started.
    260. Preprocessor symbol `__DEBUG' is defined.
    261. Fri Jun 17 21:34:01 2011
    262. ----------------------------------------------------------------------
    263. Clean: Deleting intermediary and output files.
    264. Clean: Done.
    265. Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F452 "lab2.asm" /l"lab2.lst" /e"lab2.err" /d__DEBUG=1
    266. Warning[205] C:\USERS\SAMUEL\DESKTOP\COMP245\LAB2\LAB2.ASM 1 : Found directive in column 1. (LIST)
    267. Warning[215] C:\USERS\SAMUEL\DESKTOP\COMP245\LAB2\LAB2.ASM 1 : Processor superseded by command line. Verify processor symbol.
    268. Message[301] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F887.INC 33 : MESSAGE: (Processor-header file mismatch. Verify selected processor.)
    269. Warning[230] C:\USERS\SAMUEL\DESKTOP\COMP245\LAB2\LAB2.ASM 4 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
    270. Error[126] C:\USERS\SAMUEL\DESKTOP\COMP245\LAB2\LAB2.ASM 4 : Argument out of range (not a valid config register address)
    271. Error[113] C:\USERS\SAMUEL\DESKTOP\COMP245\LAB2\LAB2.ASM 108 : Symbol not previously defined (text)
    272. Warning[226] C:\USERS\SAMUEL\DESKTOP\COMP245\LAB2\LAB2.ASM 227 : Destination address must be word aligned
    273. Halting build on first failure as requested.
    274. ----------------------------------------------------------------------
    275. Debug build of project `C:\Users\samuel\Desktop\comp245\lab2\lab2.mcp' failed.
    276. Preprocessor symbol `__DEBUG' is defined.
    277. Fri Jun 17 21:34:02 2011
    278. ----------------------------------------------------------------------
    279. BUILD FAILED
    280.  
    281.  
    Please any help before Tuesday June 21st would help
     
    Last edited by a moderator: Jun 18, 2011
  2. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    Will any one help me on how to fix my errors?
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    You probably did not set the device type in MPLAB (Configure > Select Device ...) and MPLAB is trying to assemble your code for a PIC18F452 instead of the PIC16F887 that you wrote the code for.
     
  4. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    No the device is set for pic16f887
     
  5. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    No AlexR is correct, you didn’t set the device correctly, look at the status bar in MPLAB you will see 18F452 rather 16F887.

    Another thing, their is a call you made to "text" routine but their is no "text" routine their is only "Text" routine, remember assembly is a case sensitive language.

    Error
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    2. [COLOR=black][FONT=Verdana]call text; get a character from the text table [/FONT][/COLOR]
    3. [COLOR=black][FONT=Verdana][/FONT][/COLOR]

    It should be
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    2. [COLOR=black][FONT=Verdana]call Text; get a character from the text table [/FONT][/COLOR]
    3. [COLOR=black][FONT=Verdana][/FONT][/COLOR]


    I am attaching the MPLAB project....

    Good Luck
     
    • lcd.zip
      File size:
      23.3 KB
      Views:
      49
  6. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Not according to the MPLAB assembler its not!
    See the assembler message near the bottom of the code in your first post;
    Code ( (Unknown Language)):
    1.  
    2. Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F425 "lab2.asm" /l"lab2.lst" /e"lab2.err" /d__DEBUG=1
    3.  
    That clearly states that the assembler is assembling code for a PIC18F425 not for a PIC16F887. The only way that will happen is if you don't set up the right device type in MPLAB.
     
  7. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    I did check the select device and it is set for pic16f887.
     
  8. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    I could see it says that it is set for the pic18 on the output but in the select devices it is set for the 16f887.
     
  9. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    I already attached the zip file for you,download it and run the project.... it didnt gave me any problem...
     
  10. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    Hey guys thank you for your help. Everything works now expect Wambululu does not get outputted on the Display but bdnson does. My hunch might be telling me there is something wrong with my "call Text" line. I have a picture of the output in the attachment same as the code that works now it only shows BDNSON.
     
    Last edited: Jun 20, 2011
  11. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    Your project worked. I just had reformat it a little bit(spacing,tabs etc..)
     
  12. pancikok

    New Member

    Oct 31, 2009
    26
    0
    i think you have put the goto NextMessage and call Text in wrong positions so instead of this:
    Code ( (Unknown Language)):
    1. Message
    2. movf count, w ; put counter value in W
    3. goto NextMessage ; display next message if finished
    4. xorlw 0x00 ; is it a zero?
    5. btfsc STATUS, Z
    6. call text; get a character from the text table
    7. call LCD_Char
    8. incf count, f
    9. goto Message
    10.  
    it should be like this:
    Code ( (Unknown Language)):
    1. Message
    2. movf count, w ; put counter value in W
    3. call Text; get a character from the text table
    4. xorlw 0x00 ; is it a zero?
    5. btfsc STATUS, Z
    6. goto NextMessage ; display next message if finished
    7. call LCD_Char
    8. incf count, f
    9. goto Message
    10.  
    well, i guess though! )
     
  13. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    That was a good guess. But "NO", it did not change anything. same output of "BDNSON" only on the lcd display.
     
  14. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    LCD is displaying now thank you people.
     
Loading...