bi-directional scrolling text on pic16f887

Discussion in 'Embedded Systems and Microcontrollers' started by benz_0074, Jun 21, 2011.

  1. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    I'm just wondering how to get my name scrolled on both rows bi-directional.
    The code I have here works fine, i'm just looking for the modifications to make the text scroll. Im using Mplab in assembly language.

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

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Notice the increment statement in this subroutine and in MESSAGE2?
     
  3. benz_0074

    Thread Starter New Member

    Jun 17, 2011
    11
    0
    Code is fixed
     
Loading...