Need working asm file for 16f88

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,389
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:

upand_at_them

Joined May 15, 2010
248
8MHz oscillator, blinks B3:

Rich (BB code):
                                list p=16f88, r=dec
                                errorlevel -306 ; no page boundary warnings
                                errorlevel -302 ; no bank 0 warnings
                                errorlevel -202 ; no 'argument out of range' warnings

                             __config 0x2007, 0x3fff
                             __config 0x2008, 0x3fff
datahi_set macro val
  bsf 3, 6 ; STATUS<rp1>
  endm
datahi_clr macro val
  bcf 3, 6 ; STATUS<rp1>
  endm
datalo_set macro val
  bsf 3, 5 ; STATUS<rp0>
  endm
datalo_clr macro val
  bcf 3, 5 ; STATUS<rp0>
  endm
irp_clr macro
  bcf 3, 7 ; STATUS<irp>
  endm
irp_set macro
  bsf 3, 7 ; STATUS<irp>
  endm
branchhi_set macro lbl
    bsf 10, 4 ; PCLATH<4>
  endm
branchhi_clr macro lbl
    bcf 10, 4 ; PCLATH<4>
  endm
branchlo_set macro lbl
    bsf 10, 3 ; PCLATH<3>
  endm
branchlo_clr macro lbl
    bcf 10, 3 ; PCLATH<3>
  endm
v_on                           EQU 1
v_off                          EQU 0
v_output                       EQU 0
v__portb                       EQU 0x0006  ; _portb
v__portb_shadow                EQU 0x0023  ; _portb_shadow
v_adcon0                       EQU 0x001f  ; adcon0
v_trisb                        EQU 0x0086  ; trisb
v_pin_b3_direction             EQU 0x0086  ; pin_b3_direction-->trisb:3
v_ansel                        EQU 0x009b  ; ansel
v_cmcon                        EQU 0x009c  ; cmcon
v_adcon1                       EQU 0x009f  ; adcon1
v__pic_temp                    EQU 0x0020  ; _pic_temp-->_pic_state
v__pic_state                   EQU 0x0020  ; _pic_state
v___x_54                       EQU 0x0023  ; x-->_portb_shadow:3
v___x_55                       EQU 0x0023  ; x-->_portb_shadow:3
                               org      0
l__main
                               datalo_set v_ansel
                               clrf     v_ansel
                               datalo_clr v_adcon0
                               clrf     v_adcon0
                               datalo_set v_adcon1
                               clrf     v_adcon1
                               movlw    7
                               movwf    v_cmcon
                               bcf      v_trisb, 3 ; pin_b3_direction
l__l86
                               datalo_clr v__portb_shadow ; x54
                               bsf      v__portb_shadow, 3 ; x54
                               movf     v__portb_shadow,w
                               movwf    v__portb
                               datalo_clr v__pic_temp
                               datahi_clr v__pic_temp
                               movlw    23
                               movwf    v__pic_temp
l__l96
                               movlw    103
                               movwf    v__pic_temp+1
l__l97
                               movlw    41
                               movwf    v__pic_temp+2
l__l98
                               branchhi_clr l__l98
                               branchlo_clr l__l98
                               decfsz   v__pic_temp+2,f
                               goto     l__l98
                               branchhi_clr l__l97
                               branchlo_clr l__l97
                               decfsz   v__pic_temp+1,f
                               goto     l__l97
                               branchhi_clr l__l96
                               branchlo_clr l__l96
                               decfsz   v__pic_temp,f
                               goto     l__l96
                               bcf      v__portb_shadow, 3 ; x55
                               movf     v__portb_shadow,w
                               movwf    v__portb
                               datalo_clr v__pic_temp
                               datahi_clr v__pic_temp
                               movlw    23
                               movwf    v__pic_temp
l__l99
                               movlw    103
                               movwf    v__pic_temp+1
l__l100
                               movlw    41
                               movwf    v__pic_temp+2
l__l101
                               branchhi_clr l__l101
                               branchlo_clr l__l101
                               decfsz   v__pic_temp+2,f
                               goto     l__l101
                               branchhi_clr l__l100
                               branchlo_clr l__l100
                               decfsz   v__pic_temp+1,f
                               goto     l__l100
                               branchhi_clr l__l99
                               branchlo_clr l__l99
                               decfsz   v__pic_temp,f
                               goto     l__l99
                               goto     l__l86
                               end
 
Last edited:

Markd77

Joined Sep 7, 2009
2,796
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.

Rich (BB code):
LIST p=16F88 ;tell assembler what chip we are using
#include <P16F88.inc> ;include the defaults for the chip
;set up config register 

__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
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF



cblock 0x20
d1
d2
d3
endc

org 0x0000 ;org sets the origin, 0x0000 for the 16F88,
;this is where the program starts running
goto init


init
bsf STATUS, RP0 ;select bank 1
movlw b'01110110' ;set osc to 8mhz
movwf OSCCON
movlw b'11000110' ;set up prescaler to 128 on Tmr0
movwf OPTION_REG

movlw 0x00
movwf ANSEL

movlw b'00000000' ;set PortA all outputs
movwf TRISA
movlw b'11111111'
movwf TRISB ;set PortB all inputs
bcf STATUS, RP0 ;select bank 0
clrf PORTA ;clear portA
clrf PORTB

Loop 
bsf PORTA,0
;set bit 0 on
call Delay
;
bcf PORTA,0
call Delay ;set bit0 off
goto Loop ;go back and do it again
Delay

;delay of 500msec at 8mhz clock 
;999997 cycles
movlw 0x08
movwf d1
movlw 0x2F
movwf d2
movlw 0x03
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;3 cycles
goto $+1
nop

return
end
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,389
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?
 

Markd77

Joined Sep 7, 2009
2,796
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
 

absf

Joined Dec 29, 2010
1,942
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
 

Attachments

takao21203

Joined Apr 28, 2012
3,682
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
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.
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,389
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.
:)
 
Top