PIC16F877 assembly program problem on a LED cube

Discussion in 'Programmer's Corner' started by stuffy, May 12, 2009.

  1. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    For some time now I keep trying to program my cube. But no success. I think is something that I'm declaring wrong. :confused: I have attached a sample of my program to light up a led made by me and my main program (the final one that will go on the cube; it should show on the cube the letters VALHI and numbers 209 and some animations). I have the npn tranzistors that comand the catods on ports A0 A1 A2 A3 A4 and pnp tranzistors that comand the anods on ports B0 all the way to E0 (25 in total). To light up a led I have to activate, let's say layer 1 (A0) by giving 1 and column 1 (B0) by giving 0. It is not a difficult program but I can't just get it to work. I use MPLAB to make the program.

    Main program(final one)(it is to long so I'ved upload it on a server): http://www17.zippyshare.com/v/63284413/file.html
    Pic of my cube: http://www1.zippyshare.com/v/49857516/file.html
    Please help. For any other info just ask me ;)

    Program to light up a led:
    Code ( (Unknown Language)):
    1.  
    2.  
    3.         processor       16F877
    4.            list            f=INHX32
    5.    
    6.     list      p=16F877          ; list directive to define processor
    7.        
    8.     include         p16f877.inc
    9.        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
    10.           radix           dec
    11.         __config        h'3F32' ;OSC is HS
    12.                                 ;RB3,RB6,RB7 are I/O
    13.                                 ;Brown-out detection OFF
    14.                                 ;Power-up timer ON
    15.                                 ;Code protection OFF
    16.                                 ;Data code protection OFF
    17.                                 ;Watchdog timer OFF
    18.  
    19.         errorlevel      -302    ;Eliminate bank warning
    20.         errorlevel      -307    ;Eliminate Setting page bits warning
    21. ;----------------------------------------------------------------------
    22.  
    23.         cblock  h'20'
    24.         cnt100u                         ;100us counter
    25.         endc
    26.  
    27.  
    28. ;************************  Program Start  ***************************
    29.         org     0               ;Reset Vector
    30.         goto    init
    31.  
    32. ;************************  Initial Process  *************************
    33.         org     6
    34. init
    35.  
    36. ;*** Port initialization
    37.         bsf     status,rp0      ;Change to Bank1
    38.         clrf    trisa           ;Set RA5-0 to OUTPUT
    39.         clrf    trisb           ;Set RB7-0 to OUTPUT
    40.         clrf    trisc           ;Set RC7-0 to OUTPUT
    41.         clrf    trisd           ;Set RD7-0 to OUTPUT
    42.         clrf    trise           ;Set RE2-0 to OUTPUT
    43.         bcf     status,rp0      ;Change to Bank0
    44.         clrf    porta           ;Clear PORTA
    45.         clrf    portb           ;Clear PORTB
    46.         clrf    portc           ;Clear PORTC
    47.         clrf    portd           ;Clear PORTD
    48.         clrf    porte           ;Clear PORTE
    49.  
    50.  
    51.  ;***********************************************************************
    52.  
    53. START:      movlw b'00000001'
    54.         movwf PORTA
    55.                movlw b'11111110'
    56.         movwf PORTB
    57.         movlw b'11111111'
    58.         movwf PORTC
    59.         movlw b'11111111'
    60.         movwf PORTD
    61.         movlw b'00000111'
    62.         movwf PORTE
    63.  
    64.    
    65.  
    66. GOTO    START
    67.  
    68.  
    69.  
    70.  
    71. ;********************************************************************
    72. ;                 END of Clock display check program
    73. ;********************************************************************
    74.  
    75.        end
    76.  


    Thanks

    Sorry for my english:p
     
    Last edited: May 14, 2009
  2. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    Is there anyone that could help me?

    Please. I don't know what to try anymore with my program. I just have to give 1 and 0 signals to the ports. 1 for A0,A1,A2,A3,A4 and 0 for the rest of the ports. As You cand can see I have allready come up with a program to light a led and a big one with text and animations. I just don't know how to put them togheter in the big program, how to call the declarations.

    I'm really desperate. Please help.

    Thanks
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    I have not looked at your full listing but one thing that does strike me is that you are using porta and porte as digital ports but I don't see any statements in your configuration to set them to digital. Be aware that in PICs ports that can be analog or digital default to the analog state.
     
  4. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    First let me explain more the working principle of my cube. It has 5 layers (5 led matrix 5x5) witch are the ground units controlet by 5 tranzistors npn witch are set ON by giving from the MCU "1" signals trough ports A0,A1,A2,A3,A4; and 25 columns wich are the anods + that are controled by pnp tranzistors wich are activated by giving from MCU "0" signals trough ports B0-B7,C0-C7,D0-D7 and E0.

    I have tested this by giving 5V ("1" signal) on ports A0-A4 and by giving 0V ("0" signal) on column ports and it works so the circuit is OK.
    5 minutes ago I have simulated my program with pic simulator IDE from http://www.oshonsoft.com/ and appears to be working.

    I don't know what to do anymore.
     
  5. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Have you set ports a and e to digital? If you haven't it won't work regardless of what the simulator says.
     
  6. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    Do you mean something like this:

    BCF STATUS,RP1
    BCF STATUS,RP0
    CLRF PORTA
    CLRF PORTE
    MOVLW 0x00
    MOVWF TRISA
    MOVLW 0x00
    MOVWF TRISE
     
  7. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    No I'm thinking more in terms of:

    MOVLW 0X06
    MOVWF ADCON1

    Take a look at the data sheet description of porta and the registers that it uses.
     
    Last edited: May 18, 2009
  8. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    But shouldn't ports B C and D be digital outputs to? Because I'm using all the ports of the MCU as outputs
     
  9. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Ports b and c are digital by default, they have no analog capabilities so you don,t have to worry about them. Its just the ports which can be either digital or analog that must be configured to work as digital ports.

    The fact that they default to analog and must be commanded to act as digital ports catches out every one who has ever learning PIC programming.
     
  10. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    So this is for PORTA:
    MOVLW 0X06
    MOVWF ADCON1 ;makes all the pins of PORTA as Digital I/O
    MOVLW 0x07
    MOVWF COMCON ;disables the comparators

    But I can't get it for PORTE and D
     
  11. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Setting ADCON1 to 0X06 sets AN0 - AN7 to be digital ports, this range includes all porta pins and all porte pins. Everything else is digital by default so you don't need to worry about it.
     
  12. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    So the final code to light up a led should be like this:

    Code ( (Unknown Language)):
    1.  
    2.     processor       16F877
    3.            list            f=INHX32
    4.    
    5.     list      p=16F877          ; list directive to define processor
    6.        
    7.     include         p16f877.inc
    8.        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
    9.           radix           dec
    10.         __config        h'3F32' ;OSC is HS
    11.                                 ;RB3,RB6,RB7 are I/O
    12.                                 ;Brown-out detection OFF
    13.                                 ;Power-up timer ON
    14.                                 ;Code protection OFF
    15.                                 ;Data code protection OFF
    16.                                 ;Watchdog timer OFF
    17.  
    18.         errorlevel      -302    ;Eliminate bank warning
    19.         errorlevel      -307    ;Eliminate Setting page bits warning
    20. ;----------------------------------------------------------------------
    21.  
    22.         cblock  h'20'
    23.         cnt100u                         ;100us counter
    24.         endc
    25.  
    26.  
    27. ;************************  Program Start  ***************************
    28.         org     0               ;Reset Vector
    29.         goto    init
    30.  
    31. ;************************  Initial Process  *************************
    32.         org     6
    33. init
    34.  
    35. ;*** Port initialization
    36.         bsf     status,rp0      ;Change to Bank1
    37.         clrf    trisa           ;Set RA5-0 to OUTPUT
    38.         clrf    trisb           ;Set RB7-0 to OUTPUT
    39.         clrf    trisc           ;Set RC7-0 to OUTPUT
    40.         clrf    trisd           ;Set RD7-0 to OUTPUT
    41.         clrf    trise           ;Set RE2-0 to OUTPUT
    42.         bcf     status,rp0      ;Change to Bank0
    43.         clrf    porta           ;Clear PORTA
    44.         clrf    portb           ;Clear PORTB
    45.         clrf    portc           ;Clear PORTC
    46.         clrf    portd           ;Clear PORTD
    47.         clrf    porte           ;Clear PORTE
    48.  
    49.         [COLOR="Red"]MOVLW 0X06
    50.         MOVWF ADCON1[/COLOR]
    51.  
    52.  ;***********************************************************************
    53.  
    54. START:      movlw b'00000001'
    55.         movwf PORTA
    56.                movlw b'11111110'
    57.         movwf PORTB
    58.         movlw b'11111111'
    59.         movwf PORTC
    60.         movlw b'11111111'
    61.         movwf PORTD
    62.         movlw b'00000111'
    63.         movwf PORTE
    64.  
    65.    
    66.  
    67. GOTO    START
    68.  
    69.  
    70.  
    71.  
    72. ;********************************************************************
    73. ;                 END of Clock display check program
    74. ;********************************************************************
    75.  
    76.        end
    77.  
     
  13. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    Thank you very much. I didn't know about this.

    Tomorrow I will load the final program in the MCU and hopefully it will bring to life my led cube.

    Thanks again.

    Cheers
     
  14. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    So.. I managed to get it to work. Had some hardware problems (the 15pf capacitors had to be replaced with 22pf) but the program to light up a led works great. I made another one for letter "V" and it works to.

    I have made declarations for letters V A L H I and numbers 2 0 9 and some animations for each vertical matrice of the cube. The final effect should be the letters and numbers comming from the back of the cube to the front by turning off the previous one.
    I want to call them one after the other with a short delay between them. I have made a sample with letter V and L. But I don't know how to create the delay.

    Sample V and L:

    Code ( (Unknown Language)):
    1.  
    2.  
    3.         processor       16F877
    4.         list            f=INHX32
    5.         include         p16f877.inc
    6. ;       __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
    7.         radix           dec
    8.         __config        h'3F32' ;OSC is HS
    9.                                 ;RB3,RB6,RB7 are I/O
    10.                                 ;Brown-out detection OFF
    11.                                 ;Power-up timer ON
    12.                                 ;Code protection OFF
    13.                                 ;Data code protection OFF
    14.                                 ;Watchdog timer OFF
    15.  
    16.         errorlevel      -302    ;Eliminate bank warning
    17.         errorlevel      -307    ;Eliminate Setting page bits warning
    18. ;----------------------------------------------------------------------
    19.  
    20.         cblock  h'20'
    21.         cnt100u                         ;100us counter
    22.         endc
    23.  
    24.  
    25. ;************************  Program Start  ***************************
    26.         org     0               ;Reset Vector
    27.         goto    init
    28.  
    29. ;************************  Initial Process  *************************
    30.         org     6
    31. init
    32.  
    33. ;*** Port initialization
    34.    
    35.         bsf     status,rp0      ;Change to Bank1
    36.         clrf    trisa           ;Set RA5-0 to OUTPUT
    37.     clrf    trisb           ;Set RB7-0 to OUTPUT
    38.         clrf    trisc           ;Set RC7-0 to OUTPUT
    39.         clrf    trisd           ;Set RD7-0 to OUTPUT
    40.         clrf    trise           ;Set RE2-0 to OUTPUT
    41.         bcf     status,rp0      ;Change to Bank0
    42.         clrf    porta           ;Clear PORTA
    43.         clrf    portb           ;Clear PORTB
    44.         clrf    portc           ;Clear PORTC
    45.         clrf    portd           ;Clear PORTD
    46.         clrf    porte           ;Clear PORTE
    47.  
    48.     MOVLW 0X06
    49.     MOVWF ADCON1        ;makes all the pins of PORTA as Digital I/O
    50.    
    51.  
    52.  ;***********************************************************************
    53.  
    54. START:  call PROCV1
    55.  
    56.     call PROCL1
    57.  
    58.  
    59.     goto START
    60.  
    61.  
    62. PROCV1: movlw b'00000111'
    63.     movwf PORTA
    64.         movlw b'11101110'
    65.     movwf PORTB
    66.     movlw b'11111111'
    67.     movwf PORTC
    68.     movlw b'11111111'
    69.     movwf PORTD
    70.     movlw b'00000111'
    71.     movwf PORTE
    72.  
    73.     movlw b'00000000'
    74.     movwf PORTA
    75.         movlw b'11111111'
    76.     movwf PORTB
    77.     movlw b'11111111'
    78.     movwf PORTC
    79.     movlw b'11111111'
    80.     movwf PORTD
    81.     movlw b'00000111'
    82.     movwf PORTE
    83.  
    84.     movlw b'00001000'
    85.     movwf PORTA
    86.         movlw b'11110101'
    87.     movwf PORTB
    88.     movlw b'11111111'
    89.     movwf PORTC
    90.     movlw b'11111111'
    91.     movwf PORTD
    92.     movlw b'00000111'
    93.     movwf PORTE
    94.  
    95.     movlw b'00000000'
    96.     movwf PORTA
    97.         movlw b'11111111'
    98.     movwf PORTB
    99.     movlw b'11111111'
    100.     movwf PORTC
    101.     movlw b'11111111'
    102.     movwf PORTD
    103.     movlw b'00000111'
    104.     movwf PORTE
    105.  
    106.     movlw b'00100000'
    107.     movwf PORTA
    108.         movlw b'11111011'
    109.     movwf PORTB
    110.     movlw b'11111111'
    111.     movwf PORTC
    112.     movlw b'11111111'
    113.     movwf PORTD
    114.     movlw b'00000111'
    115.     movwf PORTE
    116.  
    117.     movlw b'00000000'
    118.     movwf PORTA
    119.         movlw b'11111111'
    120.     movwf PORTB
    121.     movlw b'11111111'
    122.     movwf PORTC
    123.     movlw b'11111111'
    124.     movwf PORTD
    125.     movlw b'00000111'
    126.     movwf PORTE
    127.  
    128. return
    129.  
    130. PROCL1: movlw b'00000000'
    131.     movwf PORTA
    132.         movlw b'11111111'
    133.     movwf PORTB
    134.     movlw b'11111111'
    135.     movwf PORTC
    136.     movlw b'11111111'
    137.     movwf PORTD
    138.     movlw b'00000111'
    139.     movwf PORTE
    140.  
    141.     movlw b'00101111'
    142.     movwf PORTA
    143.         movlw b'11111110'
    144.     movwf PORTB
    145.     movlw b'11111111'
    146.     movwf PORTC
    147.     movlw b'11111111'
    148.     movwf PORTD
    149.     movlw b'00000111'
    150.     movwf PORTE
    151.  
    152.     movlw b'00000000'
    153.     movwf PORTA
    154.         movlw b'11111111'
    155.     movwf PORTB
    156.     movlw b'11111111'
    157.     movwf PORTC
    158.     movlw b'11111111'
    159.     movwf PORTD
    160.     movlw b'00000111'
    161.     movwf PORTE
    162.  
    163.     movlw b'00100000'
    164.     movwf PORTA
    165.         movlw b'11100001'
    166.     movwf PORTB
    167.     movlw b'11111111'
    168.     movwf PORTC
    169.     movlw b'11111111'
    170.     movwf PORTD
    171.     movlw b'00000111'
    172.     movwf PORTE
    173.  
    174.     movlw b'00000000'
    175.     movwf PORTA
    176.         movlw b'11111111'
    177.     movwf PORTB
    178.     movlw b'11111111'
    179.     movwf PORTC
    180.     movlw b'11111111'
    181.     movwf PORTD
    182.     movlw b'00000111'
    183.     movwf PORTE
    184.  
    185. return
    186.  
    187.  
    188. ;********************************************************************
    189. ;                 END of Clock display check program
    190. ;********************************************************************
    191.  
    192.        end
    193.  
    Can You help please.

    THANKS
     
  15. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    The simplest way to create a delay routine is to perform a nop loop for the number of times that gives the desired delay. Long delays may need nested loops. You can work out the timing by counting instruction machine cycles or go to http://www.piclist.com/techref/piclist/codegen/delay.htm, plug in your numbers and it will spit out the code you need for the desired delay.
     
  16. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    Thanks. I will try it
     
  17. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    So... I got a delay routine from the generator. This is how my program looks now:

    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4.     processor       16F877
    5.         list            f=INHX32
    6.         include         p16f877.inc
    7. ;        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
    8.         radix           dec
    9.         __config        h'3F32' ;OSC is HS
    10.                                 ;RB3,RB6,RB7 are I/O
    11.                                 ;Brown-out detection OFF
    12.                                 ;Power-up timer ON
    13.                                 ;Code protection OFF
    14.                                 ;Data code protection OFF
    15.                                 ;Watchdog timer OFF
    16.  
    17.         errorlevel      -302    ;Eliminate bank warning
    18.         errorlevel      -307    ;Eliminate Setting page bits warning
    19.  
    20. ;***********************************************************************
    21.  
    22.         cblock  h'20'
    23.         cnt100u                         ;100us counter
    24.         endc
    25.  
    26. ;************************  Program Start  ***************************
    27.         ;org     0               ;Reset Vector
    28.         ;goto    init
    29.  
    30. ;************************  Initial Process  *************************
    31.         ;org     6
    32.     ;init
    33.  
    34. ;************************  Port initialization  *************************
    35.    
    36.         bsf     status,rp0      ;Change to Bank1
    37.         clrf    trisa           ;Set RA5-0 to OUTPUT
    38.     clrf    trisb           ;Set RB7-0 to OUTPUT
    39.         clrf    trisc           ;Set RC7-0 to OUTPUT
    40.         clrf    trisd           ;Set RD7-0 to OUTPUT
    41.         clrf    trise           ;Set RE2-0 to OUTPUT
    42.         bcf     status,rp0      ;Change to Bank0
    43.         clrf    porta           ;Clear PORTA
    44.         clrf    portb           ;Clear PORTB
    45.         clrf    portc           ;Clear PORTC
    46.         clrf    portd           ;Clear PORTD
    47.         clrf    porte           ;Clear PORTE
    48.  
    49.     MOVLW 0X06
    50.     MOVWF ADCON1        ;makes all the pins of PORTA as Digital I/O
    51.    
    52.  
    53.  
    54. [COLOR="#ff0000"];************************  Delay routine  *************************[/COLOR]
    55.  
    56. ; Delay = 0.5 seconds
    57. ; Clock frequency = 20 MHz
    58.  
    59. ; Actual delay = 0.5 seconds = 2500000 cycles
    60. ; Error = 0 %
    61.  
    62.     cblock
    63.     d1
    64.     d2
    65.     d3
    66.     endc
    67.  
    68. Delay
    69.             ;2499992 cycles
    70.     movlw   0x15
    71.     movwf   d1
    72.     movlw   0x74
    73.     movwf   d2
    74.     movlw   0x06
    75.     movwf   d3
    76. Delay_0
    77.     decfsz  d1, f
    78.     goto    $+2
    79.     decfsz  d2, f
    80.     goto    $+2
    81.     decfsz  d3, f
    82.     goto    Delay_0
    83.  
    84.             ;4 cycles
    85.     goto    $+1
    86.     goto    $+1
    87.  
    88.             ;4 cycles (including call)
    89.     return
    90.  
    91.  
    92. ;************************  Main program  *************************
    93.  
    94.  
    95.  
    96. [COLOR="Red"]START: call procv1
    97.     call delay
    98.     clrf porta
    99.     clrf portb
    100.     clrf portc
    101.     clrf portd
    102.     clrf porte
    103.     goto start
    104. [/COLOR]
    105.  
    106.  
    107. PROCV1: movlw b'00000111'
    108.     movwf PORTA
    109.         movlw b'11101110'
    110.     movwf PORTB
    111.     movlw b'11111111'
    112.     movwf PORTC
    113.     movlw b'11111111'
    114.     movwf PORTD
    115.     movlw b'00000111'
    116.     movwf PORTE
    117.  
    118.     movlw b'00000000'
    119.     movwf PORTA
    120.         movlw b'11111111'
    121.     movwf PORTB
    122.     movlw b'11111111'
    123.     movwf PORTC
    124.     movlw b'11111111'
    125.     movwf PORTD
    126.     movlw b'00000111'
    127.     movwf PORTE
    128.  
    129.     movlw b'00001000'
    130.     movwf PORTA
    131.         movlw b'11110101'
    132.     movwf PORTB
    133.     movlw b'11111111'
    134.     movwf PORTC
    135.     movlw b'11111111'
    136.     movwf PORTD
    137.     movlw b'00000111'
    138.     movwf PORTE
    139.  
    140.     movlw b'00000000'
    141.     movwf PORTA
    142.         movlw b'11111111'
    143.     movwf PORTB
    144.     movlw b'11111111'
    145.     movwf PORTC
    146.     movlw b'11111111'
    147.     movwf PORTD
    148.     movlw b'00000111'
    149.     movwf PORTE
    150.  
    151.     movlw b'00100000'
    152.     movwf PORTA
    153.         movlw b'11111011'
    154.     movwf PORTB
    155.     movlw b'11111111'
    156.     movwf PORTC
    157.     movlw b'11111111'
    158.     movwf PORTD
    159.     movlw b'00000111'
    160.     movwf PORTE
    161.  
    162.     movlw b'00000000'
    163.     movwf PORTA
    164.         movlw b'11111111'
    165.     movwf PORTB
    166.     movlw b'11111111'
    167.     movwf PORTC
    168.     movlw b'11111111'
    169.     movwf PORTD
    170.     movlw b'00000111'
    171.     movwf PORTE
    172.  
    173.  
    174.  
    175.  
    176. return
    177.  
    178.  
    179. ;********************************************************************
    180.  
    181.  
    182.        end
    183.  
    And I don't get it. Shouldn't this blink procv1 at a interval of 0.5s??? It doesn't light up not even a single LED.
     
  18. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    One thing that does stand out is that the cblock statements in the delay routine should be combined with your cblock statement at the beginning of the program, otherwise you may get your cnt100u variable overwritten.
     
  19. stuffy

    Thread Starter Member

    May 12, 2009
    12
    0
    Something like this:

    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4.     processor       16F877
    5.         list            f=INHX32
    6.         include         p16f877.inc
    7. ;        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
    8.         radix           dec
    9.         __config        h'3F32' ;OSC is HS
    10.                                 ;RB3,RB6,RB7 are I/O
    11.                                 ;Brown-out detection OFF
    12.                                 ;Power-up timer ON
    13.                                 ;Code protection OFF
    14.                                 ;Data code protection OFF
    15.                                 ;Watchdog timer OFF
    16.  
    17.         errorlevel      -302    ;Eliminate bank warning
    18.         errorlevel      -307    ;Eliminate Setting page bits warning
    19.  
    20. ;***********************************************************************
    21.  
    22. ;************************  Program Start  ***************************
    23.         ;org     0               ;Reset Vector
    24.         ;goto    init
    25.  
    26. ;************************  Initial Process  *************************
    27.         ;org     6
    28.     ;init
    29.  
    30. ;************************  Port initialization  *************************
    31.    
    32.         bsf     status,rp0      ;Change to Bank1
    33.         clrf    trisa           ;Set RA5-0 to OUTPUT
    34.     clrf    trisb           ;Set RB7-0 to OUTPUT
    35.         clrf    trisc           ;Set RC7-0 to OUTPUT
    36.         clrf    trisd           ;Set RD7-0 to OUTPUT
    37.         clrf    trise           ;Set RE2-0 to OUTPUT
    38.         bcf     status,rp0      ;Change to Bank0
    39.         clrf    porta           ;Clear PORTA
    40.         clrf    portb           ;Clear PORTB
    41.         clrf    portc           ;Clear PORTC
    42.         clrf    portd           ;Clear PORTD
    43.         clrf    porte           ;Clear PORTE
    44.  
    45.     MOVLW 0X06
    46.     MOVWF ADCON1        ;makes all the pins of PORTA as Digital I/O
    47.    
    48.  
    49.  
    50. [COLOR="Red"];************************  Delay routine  *************************
    51.  
    52. ; Delay = 0.5 seconds
    53. ; Clock frequency = 20 MHz
    54.  
    55. ; Actual delay = 0.5 seconds = 2500000 cycles
    56. ; Error = 0 %
    57.  
    58.     cblock
    59.     cnt100u
    60.     cnt100u_1
    61.     cnt100u_2
    62.     endc
    63.  
    64. Delay
    65.             ;2499992 cycles
    66.     movlw   0x15
    67.     movwf   cnt100u
    68.     movlw   0x74
    69.     movwf   cnt100u_1
    70.     movlw   0x06
    71.     movwf   cnt100u_2
    72. Delay_0
    73.     decfsz  cnt100u, f
    74.     goto    $+2
    75.     decfsz  cnt100u_1, f
    76.     goto    $+2
    77.     decfsz  cnt100u_2, f
    78.     goto    Delay_0
    79.  
    80.             ;4 cycles
    81.     goto    $+1
    82.     goto    $+1
    83.  
    84.             ;4 cycles (including call)
    85.     return
    86.  
    87. ;************************  Main program  *************************[/COLOR]
    88.  
    89.  
    90.  
    91. START:  call procv1
    92.     call delay
    93.     clrf porta
    94.     clrf portb
    95.     clrf portc
    96.     clrf portd
    97.     clrf porte
    98.     goto start
    99.  
    100.  
    101.  
    102. PROCV1: movlw b'00000111'
    103.     movwf PORTA
    104.         movlw b'11101110'
    105.     movwf PORTB
    106.     movlw b'11111111'
    107.     movwf PORTC
    108.     movlw b'11111111'
    109.     movwf PORTD
    110.     movlw b'00000111'
    111.     movwf PORTE
    112.  
    113.     movlw b'00000000'
    114.     movwf PORTA
    115.         movlw b'11111111'
    116.     movwf PORTB
    117.     movlw b'11111111'
    118.     movwf PORTC
    119.     movlw b'11111111'
    120.     movwf PORTD
    121.     movlw b'00000111'
    122.     movwf PORTE
    123.  
    124.     movlw b'00001000'
    125.     movwf PORTA
    126.         movlw b'11110101'
    127.     movwf PORTB
    128.     movlw b'11111111'
    129.     movwf PORTC
    130.     movlw b'11111111'
    131.     movwf PORTD
    132.     movlw b'00000111'
    133.     movwf PORTE
    134.  
    135.     movlw b'00000000'
    136.     movwf PORTA
    137.         movlw b'11111111'
    138.     movwf PORTB
    139.     movlw b'11111111'
    140.     movwf PORTC
    141.     movlw b'11111111'
    142.     movwf PORTD
    143.     movlw b'00000111'
    144.     movwf PORTE
    145.  
    146.     movlw b'00100000'
    147.     movwf PORTA
    148.         movlw b'11111011'
    149.     movwf PORTB
    150.     movlw b'11111111'
    151.     movwf PORTC
    152.     movlw b'11111111'
    153.     movwf PORTD
    154.     movlw b'00000111'
    155.     movwf PORTE
    156.  
    157.     movlw b'00000000'
    158.     movwf PORTA
    159.         movlw b'11111111'
    160.     movwf PORTB
    161.     movlw b'11111111'
    162.     movwf PORTC
    163.     movlw b'11111111'
    164.     movwf PORTD
    165.     movlw b'00000111'
    166.     movwf PORTE
    167.  
    168.  
    169.  
    170.  
    171. return
    172.  
    173.  
    174. ;********************************************************************
    175.  
    176.  
    177.        end
    178.  
    179.  
     
Loading...