Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Can anyone tell me what's wrong with this simple code?

Status
Not open for further replies.

RobertD

New Member
Is there something I am missing here to get all 7 pins to light up? All I get with this program is pin 012346 on, 57 off...

Puzzled....?!?!


processor 16F88
include p16F88.inc



CLRF STATUS
CLRF TRISA
BSF STATUS,5
MOVLW H'00'
MOVWF TRISA
BCF STATUS,5
MOVLW H'FF'
MOVWF PORTA

END
 
You also need to set the CONFIG fuses, see the example in the back of the Firefly manual.
Code:
    LIST     P=16F88
    INCLUDE <p16F88.inc>
    __CONFIG _CONFIG1, _CCP1_RB0 & _WDT_OFF &_LVP_OFF &_INTRC_IO


    CLRF STATUS    
    CLRF TRISA
    BSF STATUS,RP0
    MOVLW H'00'
    MOVWF TRISA
    BCF STATUS,RP0
    MOVLW H'FF'
    MOVWF PORTA

    END
 
Hi,
Please provide more information, such as what are you trying to do?
What are the configuration words?
RA5 can be used as input only, not output on or off.
The analog should be disabled if you want to use only the digital. Select analog from ANSEL and CMCON.
 
There are a lot of things missing, Config, Org, turning off the analogue pins, stopping the program running off into memory.

Here's a starting point,
Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON

	cblock	0x20
;variables go here
d1
d2
d3
	endc

	org	0x0000		;start of program
init
	bsf	STATUS,RP0	;bank 1
	movlw	0x72		;8MHz internal osc
	movwf	OSCCON
	movlw	0x07		;turn comparators off
	movwf	CMCON
	clrf	ANSEL		;all pins digital
	movlw	0x00		;all pins outputs
	movwf	TRISA ;& 0x7f
	movwf	TRISB
	bcf	STATUS,RP0	;select bank 0

main	bsf	PORTA,1
	call	delay
	bcf	PORTA,1
	call	delay
	goto	main

delay	movlw	0x15
	movwf	d1
	movlw	0x74
	movwf	d2
	movlw	0x02
	movwf	d3
delay_0	decfsz	d1,f
	goto	dd2
	decfsz	d2,f
dd2	goto	dd3
	decfsz	d3,f
dd3	goto	delay_0
	return

	end

Mike.
 
Last edited:
OK thanks, I'm very new at this... I was just trying to get the PORTA pins to light up, I knew about the config, and the initial setup, but didn't know how to set it up. Now I have a good starting point. I'm building a "case specific" module, and I have to do my baby steps before I can get into the meat of it, and this was my baby steps, still lots to learn. But this definitely gives me a good starting point.
 
OK thanks, I'm very new at this... I was just trying to get the PORTA pins to light up, I knew about the config, and the initial setup, but didn't know how to set it up. Now I have a good starting point. I'm building a "case specific" module, and I have to do my baby steps before I can get into the meat of it, and this was my baby steps, still lots to learn. But this definitely gives me a good starting point.
Hi,
Here you have the tutorial for assembly language. Also read the datasheet.
 
Thanks I've added the page. I do have the data sheet, but couldn't find the config set up in there. Found config1 and config2, but not config. And I sorta knew about the clock set up but not about the analog set up and turning the comparators off. But I'm getting straightened up pretty quick, thanks to you guys.


I get the feeling I'll be spending the next two years of my life learning about pic programming... :)
A couple of hours a night.

PS: Thanks Mike, I copied the file and will adapt it.
 
Last edited:
Found config1 and config2, but not config.
Hi,
_CONFIG1 and _CONFIG2 are the configuration settings of thie PIC. PIC16F88 has a lot of special features that needed to be set up, 14 bits is not enough so there're two configuration settings.
And I sorta knew about the clock set up but not about the analog set up and turning the comparators off. But I'm getting straightened up pretty quick, thanks to you guys.
The reason of setting them up because it is not digital by default. So you need to disable the analog and the comparator even they are not used.
 
Hi Mike,

I'm running your program as is, and it's supposed to give me a flashing led, but all I get is pin 6 on steady.

I'm beginning to think I might want to try straight serial port to PIC, to see if I get better response. Just four wires without anything else.

I just checked Gooligum, and it looks like I'm going to get in there quite a lot, it's just the format I like. Right to the point. And I have a lot of learning to do, from here to my working prototype.
 
Last edited:
Hi Mike,

I'm running your program as is, and it's supposed to give me a flashing led, but all I get is pin 6 on steady.

I'm beginning to think I might want to try straight serial port to PIC, to see if I get better response. Just four wires without anything else.
It's blinking fast and you can't feel it.
 
OK Pin 6 is still on steady... as well as pin 1

Running your program as is, with the clock modification.

Wait a sec... pin 1 is flashing very very slowly...

:)

There is hope... I must accelerate it a bit.
 
Last edited:
thanks, I was looking either for a slower clock setting, or a lower initial delay set up... Will do.

Fantastic, that gives me about 3 seconds delay, I need a 1 second delay... can I shorten the delay
 
Last edited:
Looking at the routine, I was wondering where I can cut the timer down a bit.... I have to figure out the logic on this one. To cut the time in half. Maybe reduce D3 to 01


delay
movlw 0x15
movwf d1
movlw 0x74
movwf d2
movlw 0x02
movwf d3

delay_0
decfsz d1,f
goto dd2
decfsz d2,f

dd2
goto dd3
decfsz d3,f

dd3
goto delay_0

return
 
Last edited:
Success... :)

Thanks guys I could not have done it without you.... :)

Now I have a blinking LED at 1/s.

Bedtime...
 
Last edited:
While the delay generators are great for coming up with a quick-n-dirty fixed delay, I have found that having a good general purpose delay routine in the tool box can often be much handier.

Here's a delay subsystem I designed to support almost any clock (simply by setting an equate) and allows you to specify delays in cycles, microseconds, or milliseconds.

The subsystem includes a small 12 word subroutine and a macro "front end";

Code:
;******************************************************************
;                                                                 *
;  Delay(16..262159 Tcy) subroutine   Mike McLaren, K8LH, Jun'07  *
;                                                                 *
;  12 words, 1 RAM variable, 14-bit core                          *
;                                                                 *
Delay.16
        nop                     ; entry point for delay%4 == 3    |B0
        nop                     ; entry point for delay%4 == 2    |B0
        nop                     ; entry point for delay%4 == 1    |B0
DelayLo addlw   -1              ; subtract 4 cycle loop time      |B0
        skpnc                   ; borrow?  yes, skip, else        |B0
        goto    DelayLo         ; do another loop                 |B0
        nop                     ;                                 |B0
DelayHi addlw   -1              ; subtract 4 cycle loop time      |B0
        decfsz  TMRH,F          ; done?  yes, skip, else          |B0
        goto    DelayLo         ; do another loop                 |B0
        goto    $+1             ; burn off 2 cycles               |B0
        return                  ;
;                                                                 *
;******************************************************************
        radix   dec

clock   equ     8               ; 4, 8, 12, 16 or 20 MHz
;
;  DelayCy() operand multipliers
;
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
;                                                                 *
;  DelayCy() macro                                                *
;                                                                 *
DelayCy macro   pDelay          ; cycles (Tcy), minimum 16
        local   cycles
        cycles = pDelay
     while cycles > 262032
        movlw   high((262016-16)/4)+1
        movwf   TMRH
        movlw   low((262016-16)/4)
        call    DelayLo-(262016%4)
        cycles -= 262016
     endw
        movlw   high((cycles-16)/4)+1
        movwf   TMRH
        movlw   low ((cycles-16)/4)
        call    DelayLo-(cycles%4)
        endm
;                                                                 *
;  example code for simulation testing;                           *
;                                                                 *
SimTest DelayCy(2*msecs)        ; remember to set 'clock' equate
        nop                     ; put simulator break point here
;                                                                 *
;******************************************************************
Here's an example of how you might use the subsystem (below). Please note that we could just as easily have used a plain old 1 msec delay without accounting for the 6 cycle loop time but if you don't account for those cycles then you'll actually get slightly different frequency tones depending on your clock frequency. Accounting for those cycles in the delay parameter lets us produce exact 500 Hz tones no matter what clock we're using.

Code:
;
;  toggle the speaker pin at 1 msec intervals to produce a 500 Hz
;  key press beep
;
        bsf     Beep,5          ; do 32 msec switch press beep    |B0
DoBeep  movf    PORTA,W         ; read port A                     |B0
        xorlw   1<<Spkr         ; toggle speaker bit              |B0
        movwf   PORTA           ; toggle speaker pin              |B0
        DelayCy(1*msecs-6)      ; delay 1 msec minus 6 cycles     |B0
        decfsz  Beep,F          ; done?  yes, skip, else          |B0
        goto    DoBeep          ; loop (toggle Spkr pin again)    |B0
Code:
;
;  blinky example
;
loop
        bsf     PORTB,0         ; turn RB0 LED "off"
        DelayCy(500*msecs)      ; 1/2 second delay
        bcf     PORTB,0         ; turn RB0 LED "on"
        DelayCy(500*msecs)      ; 1/2 second delay
        goto    loop            ;

Good luck with your projects and have fun... Mike
 
Status
Not open for further replies.

Latest threads

Back
Top