Pic16f72 hitech C...

Status
Not open for further replies.

koolguy

Active Member
Hi,

I am using PIC16F72 the
__delay_ms(55);
is not working showing error after removing it the code work fine for led flash/blink...?
i am using #include <htc.h> header file...
 
#define _FREQ_XTAL xxxxx

You NEED to define the clock speed...
 
here is the code.....

Code:
#include <htc.h>

__CONFIG( BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS & CP_OFF );

#define _XTAL_FREQ 20000000;



void main()
    {
    TRISC = 0 ;

while(1){
PORTC=0XFF;
__delay_ms(500);
PORTC=0X00;
__delay_ms(500);

}
}
 
C:
#include <htc.h>
__CONFIG( BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS & CP_OFF );
#define _XTAL_FREQ 20000000 //; <--- This semi colon  shouldn't be here

void main()
    {
    TRISC = 0 ;

    while(1){
        PORTC=0XFF;
        __delay_ms(500);
        PORTC=0X00;
        __delay_ms(500);

        }
    }

Simples!!!
 
Hi i want to calculate delay given by this subroutine....
total 16 inst cycle taken is this right? if yes that mean 16 x .2 x10-6

Code:
DELAY MOVLW 0X01                  ;  1 inst cycle
              MOVWF count1                 ;  1 inst cycle      2
   
delay    MOVLW 0X02                     ;  1 inst cycle  2+
              MOVWF counta                    ;  1 inst cycle            
     
delay_0
             DECFSZ counta,f                 ;  2 inst cycle    2+2
             GOTO delay_0                 ;  2 inst cycle    2+
             DECFSZ count1,f                   ;  2 inst cycle   2+
             GOTO delay                        ;  2 inst cycle   2+
     
RETURN                 ;  2 inst cycle  2
 
According to data sheet MOVlW/WF take 1 inst and GOTO /CALL/RETURN/DECFSZ take 2 instruction cycle...
 
Not quite. The conditional tests take one cycle if false and two cycles if true:




John
 
yes, it is right it is taking 1 cyle on incorrect


Delay
;19 cycles
movlw 0x06
movwf d1
Delay_0
decfsz d1, f
goto Delay_0
 
Last edited:

I am not sure what you are saying. Is your comment a question or a statement. When D1 =0 , what do you want to happen? Presumably, this delay is a subroutine, so you need a return. That return will also add two cycles. The call also takes two cycles. I agree, it is 19 cycles from movlw to the NOP that I added.
 
I am saying that you are correct as per your instruction cycle was right and it is taking DECFSZ 1 instruction when the contd is wrong.
 
That was not a right or wrong opinion. It was in the datasheet. The program counter is advanced before fetching the instruction. If the result of the instruction requires a change to the program counter, then it seems logical that another cycle is needed.

Here are some relevant quotes from the Mid-Range MCU Family Reference Manual. The datasheet for each MCU has a similar discussion about single-cycle instructions.

PC incremented before fetching instruction (page 4-5):
Internally, the program counter (PC) is incremented
every Q1, and the instruction is fetched from the program memory and latched into the
instruction register in Q4.

Pipelining (page 4-6):

John
 

Extra semicolons are not a problem.. they do nothing.

EDIT: Sorry, that semicolon was in a define statement. That is a problem.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…