PIC16F690 'delay'

I have spent the past day(i know it sounds stupid) figuring out how to make a 1sec delay on the PIC16F690 to make an led blink. hope you guys can help.

this is my code :

*************************************

'

; EQUATES SECTION

TMR0 EQU 1

STATUS EQU 3

PORTA EQU 5

PORTB EQU 6

PORTc EQU 7

TRISA EQU 85h

TRISB EQU 86h

TRISC EQU 87h

OPTION_R EQU 81h

ZEROBIT EQU 2

COUNT EQU 0CH

************************************

'

LIST P = 16F690

ORG 0

GOTO START

***********************************

'

;SUBROUTINE SECTION.

; 1 second delay.

DELAY1 CLRF TMR0

LOOPA MOVF TMR0,W

SUBLW .32

BTFSS STATUS,ZEROBIT

GOTO LOOPA

RETLW 0

**********************************

'

;CONFIGURATION SECTION

START BSF STATUS,5

MOVLW B'11111111'

MOVWF TRISA

MOVLW B'11110000'

MOVWF TRISB

MOVLW B'00000000'

MOVWF TRISC

MOVLW B'00000111'

MOVWF OPTION_R

BCF STATUS,5

CLRF PORTA

CLRF PORTB

CLRF PORTC

**********************************

'

;PROGRAM STARTS NOW.

BEGIN BSF PORTC,0

CALL DELAY1

BCF PORTC,0

CALL DELAY1

GOTO BEGIN

your program is hard to read
your program is hard to read since it is missing some spaces in multiple places. please fix these so we can better see what is wrong

Sorry for that, there
Sorry for that, there something wrong with it. Made changes alr

Since Timer0 is set to 8-bit

Since Timer0 is set to 8-bit timer mode, it increments by 1 for each instruction cycle, except for the first 2 cycles after clearing it. The ‘end condition’ you’re waiting for is when Timer0 == 32, but what about if Timer0 is increasing too fast and it goes higher than 32? When that is the case, SUBLW will not set the Zero bit on the Status register, and therefore the end condition will not trigger as expected.

Instead of using the Zero bit in “BTFSS STATUS,ZEROBIT”, try using “BTFSC STATUS,C” where C is the Carry bit in the Status register. If Timer0 is > 31 (ie: Timer0 >= 32), the Carry bit will be 1, which means the end condition will still trigger even if Timer0 is already slightly larger than 32 by the time SUBLW is computed.

so it should be something

so it should be something like this ( not too good at asm and PIC’s yet)

;1sec Delay

 

DELAY1 CLRF TMR0

LOOPA MOVF TMR0,W

TMR0 => .32

SUBLW TMR0

BTFSS STATUS,ZEROBIT(not sure about this)

GOTO LOOPA

RETLW 0

There are no operators in

There are no operators in ASM, so your “=>” won’t work. The format is always label/mnemonic/argument(s).
The replacement code I was thinking of would go like this:

DELAY1 CLRF TMR0
LOOPA MOVF TMR0,W
SUBLW .32
BTFSS STATUS,C
GOTO LOOPA
RETLW 0

You’d also have to define ‘C’ with “C EQU 0” or something to that effect in order to make the Carry bit reference work.

get a new PIC
Most of the PIC’s In the 18FXX series have a comparitor. since the cips are relitively inexpensive I recommend getting a new one with more features. you get to do things like skip on equal or lessthan or greaterthan. It will make your programs easier to read and quicker to write.

Although they make
Although they make programming more convenient they don’t add any new functionality; in the end the ‘new’ conditional branches are still testing the status bits in the same way.

ALRIGHT WILL TRY THAT ONCE I
ALRIGHT WILL TRY THAT ONCE I GET HOMEWORK DONE :stuck_out_tongue:

I tried this already but it
I tried this already but it does not work. I think that i did not set the internal oscilitator to 32? how do i do that?

Helpful Hint…

Just as a suggestion, I will share one of my favoirte quotes from the preface of one of my favorite PIC books: The PIC Microcontroller: Your Personal Introductory Course.

“I am happy to help, and will try to answer any questions you may have. However, I have also been sent PIC programs without a single comment on them, and often without any indication of what task they they are actually meant to perform, with a short message along the lines of: ‘It doesn’t work.’” … “These types of [inquiries] will seldom meet with a favorable response, simply because I haven’t a clue what to do. So please put comments everywhere in your programs and try to isolate exactly what is going wrong”

Is there mode code than what
Is there mode code than what you’ve given us here? If not, then you haven’t set any of the configuration bits.
Depending on your programmer you can either set the config bits in the code or have the programmer set them for you; I suggest you do some reading on the config bits, they’re quite important.

starting with PIC’s

Hi,

If you are starting with pics, than this might be of interest to you. It definately got me starting on PIC’s before I went to ASM.

Cheers,

YCD