Need working asm file for 16f88

Discussion in 'Programmer's Corner' started by Dodgydave, Jun 29, 2012.

  1. Dodgydave

    Thread Starter AAC Fanatic!

    Jun 22, 2012
    5,005
    745
    Any one got a simple asm file for a pic16f88 that will put an led on port A or B or flash it, please as i cant find any working files for this pic?

    i am using pic assembly code, not C

    YOURS Desperate.....:(,
     
    Last edited: Jun 29, 2012
  2. upand_at_them

    Active Member

    May 15, 2010
    246
    29
    8MHz oscillator, blinks B3:

    Code ( (Unknown Language)):
    1.                                 list p=16f88, r=dec
    2.                                 errorlevel -306 ; no page boundary warnings
    3.                                 errorlevel -302 ; no bank 0 warnings
    4.                                 errorlevel -202 ; no 'argument out of range' warnings
    5.  
    6.                              __config 0x2007, 0x3fff
    7.                              __config 0x2008, 0x3fff
    8. datahi_set macro val
    9.   bsf 3, 6 ; STATUS<rp1>
    10.   endm
    11. datahi_clr macro val
    12.   bcf 3, 6 ; STATUS<rp1>
    13.   endm
    14. datalo_set macro val
    15.   bsf 3, 5 ; STATUS<rp0>
    16.   endm
    17. datalo_clr macro val
    18.   bcf 3, 5 ; STATUS<rp0>
    19.   endm
    20. irp_clr macro
    21.   bcf 3, 7 ; STATUS<irp>
    22.   endm
    23. irp_set macro
    24.   bsf 3, 7 ; STATUS<irp>
    25.   endm
    26. branchhi_set macro lbl
    27.     bsf 10, 4 ; PCLATH<4>
    28.   endm
    29. branchhi_clr macro lbl
    30.     bcf 10, 4 ; PCLATH<4>
    31.   endm
    32. branchlo_set macro lbl
    33.     bsf 10, 3 ; PCLATH<3>
    34.   endm
    35. branchlo_clr macro lbl
    36.     bcf 10, 3 ; PCLATH<3>
    37.   endm
    38. v_on                           EQU 1
    39. v_off                          EQU 0
    40. v_output                       EQU 0
    41. v__portb                       EQU 0x0006  ; _portb
    42. v__portb_shadow                EQU 0x0023  ; _portb_shadow
    43. v_adcon0                       EQU 0x001f  ; adcon0
    44. v_trisb                        EQU 0x0086  ; trisb
    45. v_pin_b3_direction             EQU 0x0086  ; pin_b3_direction-->trisb:3
    46. v_ansel                        EQU 0x009b  ; ansel
    47. v_cmcon                        EQU 0x009c  ; cmcon
    48. v_adcon1                       EQU 0x009f  ; adcon1
    49. v__pic_temp                    EQU 0x0020  ; _pic_temp-->_pic_state
    50. v__pic_state                   EQU 0x0020  ; _pic_state
    51. v___x_54                       EQU 0x0023  ; x-->_portb_shadow:3
    52. v___x_55                       EQU 0x0023  ; x-->_portb_shadow:3
    53.                                org      0
    54. l__main
    55.                                datalo_set v_ansel
    56.                                clrf     v_ansel
    57.                                datalo_clr v_adcon0
    58.                                clrf     v_adcon0
    59.                                datalo_set v_adcon1
    60.                                clrf     v_adcon1
    61.                                movlw    7
    62.                                movwf    v_cmcon
    63.                                bcf      v_trisb, 3 ; pin_b3_direction
    64. l__l86
    65.                                datalo_clr v__portb_shadow ; x54
    66.                                bsf      v__portb_shadow, 3 ; x54
    67.                                movf     v__portb_shadow,w
    68.                                movwf    v__portb
    69.                                datalo_clr v__pic_temp
    70.                                datahi_clr v__pic_temp
    71.                                movlw    23
    72.                                movwf    v__pic_temp
    73. l__l96
    74.                                movlw    103
    75.                                movwf    v__pic_temp+1
    76. l__l97
    77.                                movlw    41
    78.                                movwf    v__pic_temp+2
    79. l__l98
    80.                                branchhi_clr l__l98
    81.                                branchlo_clr l__l98
    82.                                decfsz   v__pic_temp+2,f
    83.                                goto     l__l98
    84.                                branchhi_clr l__l97
    85.                                branchlo_clr l__l97
    86.                                decfsz   v__pic_temp+1,f
    87.                                goto     l__l97
    88.                                branchhi_clr l__l96
    89.                                branchlo_clr l__l96
    90.                                decfsz   v__pic_temp,f
    91.                                goto     l__l96
    92.                                bcf      v__portb_shadow, 3 ; x55
    93.                                movf     v__portb_shadow,w
    94.                                movwf    v__portb
    95.                                datalo_clr v__pic_temp
    96.                                datahi_clr v__pic_temp
    97.                                movlw    23
    98.                                movwf    v__pic_temp
    99. l__l99
    100.                                movlw    103
    101.                                movwf    v__pic_temp+1
    102. l__l100
    103.                                movlw    41
    104.                                movwf    v__pic_temp+2
    105. l__l101
    106.                                branchhi_clr l__l101
    107.                                branchlo_clr l__l101
    108.                                decfsz   v__pic_temp+2,f
    109.                                goto     l__l101
    110.                                branchhi_clr l__l100
    111.                                branchlo_clr l__l100
    112.                                decfsz   v__pic_temp+1,f
    113.                                goto     l__l100
    114.                                branchhi_clr l__l99
    115.                                branchlo_clr l__l99
    116.                                decfsz   v__pic_temp,f
    117.                                goto     l__l99
    118.                                goto     l__l86
    119.                                end
    120.  
     
    Last edited: Jun 29, 2012
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    The code that absf modified:
    http://forum.allaboutcircuits.com/showpost.php?p=499598&postcount=9

    With a little bit changed so it doesn't skip all the initialisation and go straight to the loop :
    I've checked in the simulator and it seems fine.

    Code ( (Unknown Language)):
    1. LIST p=16F88 ;tell assembler what chip we are using
    2. #include <P16F88.inc> ;include the defaults for the chip
    3. ;set up config register
    4.  
    5. __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
    6. __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
    7.  
    8.  
    9.  
    10. cblock 0x20
    11. d1
    12. d2
    13. d3
    14. endc
    15.  
    16. org 0x0000 ;org sets the origin, 0x0000 for the 16F88,
    17. ;this is where the program starts running
    18. goto init
    19.  
    20.  
    21. init
    22. bsf STATUS, RP0 ;select bank 1
    23. movlw b'01110110' ;set osc to 8mhz
    24. movwf OSCCON
    25. movlw b'11000110' ;set up prescaler to 128 on Tmr0
    26. movwf OPTION_REG
    27.  
    28. movlw 0x00
    29. movwf ANSEL
    30.  
    31. movlw b'00000000' ;set PortA all outputs
    32. movwf TRISA
    33. movlw b'11111111'
    34. movwf TRISB ;set PortB all inputs
    35. bcf STATUS, RP0 ;select bank 0
    36. clrf PORTA ;clear portA
    37. clrf PORTB
    38.  
    39. Loop
    40. bsf PORTA,0
    41. ;set bit 0 on
    42. call Delay
    43. ;
    44. bcf PORTA,0
    45. call Delay ;set bit0 off
    46. goto Loop ;go back and do it again
    47. Delay
    48.  
    49. ;delay of 500msec at 8mhz clock
    50. ;999997 cycles
    51. movlw 0x08
    52. movwf d1
    53. movlw 0x2F
    54. movwf d2
    55. movlw 0x03
    56. movwf d3
    57. Delay_0
    58. decfsz d1, f
    59. goto $+2
    60. decfsz d2, f
    61. goto $+2
    62. decfsz d3, f
    63. goto Delay_0
    64. ;3 cycles
    65. goto $+1
    66. nop
    67.  
    68. return
    69. end
     
  4. Dodgydave

    Thread Starter AAC Fanatic!

    Jun 22, 2012
    5,005
    745
    tried both of these and still not working, pic wired as follows>> pin 5 ov, pin 14 +5v, pin 4 to +5v via 10k resistor. all other pins measure 1.5 v , no output is pulsing.

    Think i will give pic programming up and chuck it in the bin!

    How do you run the simulator?
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    A few thoughts:
    Ideally you would have a 100nF capacitor connected between pin 5 and 14.
    Try changing the TRISB setting to b'00000000' - unconnected pins should be set as output to avoid oscillations.
    Change part of the config line from _MCLR_OFF to _MCLR_ON. With the resistor still in place and power connected, try touching a wire from the MCLR pin (pin 4) to ground a few times and see if resetting it helps.
    The most recent post in this thread describes how to start using the simulator.
    http://forum.allaboutcircuits.com/showthread.php?t=44852
     
  6. absf

    Senior Member

    Dec 29, 2010
    1,493
    373
    I assembled the exact program attached by Mark and simulated it in proteus. It works the first time. The states of the unused RA1-RA4 should all read 0V or else something is wrong with the Configurations or PIC is not reseting during power up.

    You dont see the Vcc and GND pins because they are hidden on my simulator.

    Follow what Mark suggested and it should be easy to make it work. I have a 16F88 board connected to 4x 7 segment LED running a 0-9999 counter program right in front of me. It has been running non-stop for more than 48 hours.

    If you gave up so easily you'll miss a lot of fun in the time to come. I have played with 6502, 6803, 8085, Z80, 6809, 8031, 89S4051 and PIC. I started PIC with a home-made JDM programmer running on serial port of my PC. My first PIC was a 16F628. It took me 4 weeks for my first program to run even with all my experiences with micro. Nowadays there are USB ICSP programmers that you can get for less than 20 bucks. And all the people here who are willing to help you.... What other favours do you want to get yourself moving on? It's your choice after all.....:D

    cheers!

    Allen
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    These capacitors are rarely needed for functionality. I never saw a PIC that refused to work at all, and then worked with 100nF applied. But yes in general there should be something, 1uF, 220uF, or whatever is available.

    Also uncontrolled oscillations I have never observed so far.

    If MCLR can be switched off, then no external resistor is needed but worth trying.

    Maybe the crystal is bad, try a 22uH coil with HS setting and no extra parts, this should work on almost all PICs.

    And simply try to switch on a LED, and then change the program to keep it OFF.

    It may sound weird but sometimes it takes me hours just to get a small PIC running. Usually they work immediately like they should, but it really happens. Often there are wiring mistakes.

    And it's also possible the PIC is broken, I have seen it a few times, but it is rather unusual.

    the 16f88 I would not buy, it's outdated. 16f1824 is good or 16f1503, or 16f54, if you want something simple. Otherwise I only use 18F now.

    Actually most of the basics I have learned using the 16f54.
     
  8. Dodgydave

    Thread Starter AAC Fanatic!

    Jun 22, 2012
    5,005
    745
    Thanks for all your input guys, have binned the pic 16f88 and gone onto the pic16f628a and this is now working flashing ok, must have been the pics at fault.
    :)
     
Loading...