Im doing a university course at the moment were we use CC5X from the command prompt in windows (reminds me why no one uses dos style shells any more). So one that will working a similar way would be preferable.
; File Created by SDCC: free open source ANSI-C Compiler; Version 3. 0 # 6037 ( Apr 13 2011 ) ( Linux ); This file was generated Thu Aug 25 00: 28: 43 2011; -; PIC port for the 14-bit core; -;.
Ladies & Gents, I have been going through timer0 and its studeis. Everytime I get close to understand the delay function given in CC5x compiler, I end up confused. I want to delay 1s the leds I got connected to chip.
But I can't figure how to calculate exactly a delay of one second. I understand the following formula Next. Presc.
1/Fosc/4 = delay and the functionality of Timer0 as I read from some tutorials and the datasheet But I'm confused. Please see the code and the questions below the following code.
Click to expand.Why would you need to guess? You chose the CC5X compiler, one I have never heard of before, yet I was able to absolutely find the definition for this symbol in a couple of minutes by simply Reading The Fine Manual (RTFM) for your compiler. You should have found it faster as that manual would have been in your download package. It means 'millisec' is an unsigned 16 bit integer. And the PIC16f690 absolutely does indeed use 2's complement.
In this case there is no such thing as a negative time delay so a negative number makes no sense so it is not allowed. 'millisec' will hold the number of milliseconds the routine will wait until it returns. Click to expand.' Next' is defined as an (unsigned) char with an initial value of zero. (CCS makes the char type unsigned by default (RTFM) )'+=' means add the value on the right to the variable on the left. 'TMR0' is the Timer1 register in the PIC that holds the current timer time; again RTFM for the PIC you are using.
The (very short) while loop waits on that line for 125 counts on Timer1 to occure. If Timer1 is set up corrently it takes 1 full milliseccond for the count to advance by 125 counts. Then the 'millisec' variable is decremented and tested to see if the total delay has passed. If not, the loop repeats.