hello everybody
i want yo use the timer of a 16f876a
how use trm0 ?
i introduce c code in flowcode in order to clear the register trm0
TRM0 = 0;
when i compile i see an error : unknown identifier 'TRM0'
i just seach in the forum but i do not see some help.
i tink the solution is easy but i am a newbee
tank for you
use of registers ?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Jack
Thanks for posting your progress. Seems like you have it sorted now.
Thanks for posting your progress. Seems like you have it sorted now.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel

Code: Select all
void main()
{
//Initialisation
adcon1 = 0x07;
//Code d'initialisation d'Interruption
option_reg = 0xC0;
//Code C
//Code C:
option_reg = 0xa0;
//Boucle
//Boucle: Tant que1
while( 1 )
{
//Code C
//Code C:
tmr0 = 0;
//Pause
//Pause: 200 ms
delay_ms(200);
//Code C
//Code C:
FCV_MYVAR = tmr0;
//Sortie
//Sortie: MYVAR -> PORT C
trisc = 0x00;
portc = FCV_MYVAR;
}
mainendloop: goto ma
for 1khz ttl on ra4 :
delay 10ms : portc = 5
delay 100ms portc= 50
delay 200ms portc = 104
there is a division by 2, at 1khz the period is 1ms and whith a delay of 10ms the count must be 10
i d'ont understant !
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
The Timer0 is only an 8 bit counter.
This means that its maximum value is 255. The counter is fairly high speed and a delay of 200ms is probably more then enough time for it to have rolled over from 255 to 0 quite a number of times.
It would be a much more reliable method to use either the timer1 which is usually a 16 bit counter or you could use a much smaller delay and then multiply the result to give the count value over a longer period. This would also leave you with a larger number then 8 bit so you would not be able to write straight to the port as you are doing now. You could however use a LCD to show the result.
This means that its maximum value is 255. The counter is fairly high speed and a delay of 200ms is probably more then enough time for it to have rolled over from 255 to 0 quite a number of times.
It would be a much more reliable method to use either the timer1 which is usually a 16 bit counter or you could use a much smaller delay and then multiply the result to give the count value over a longer period. This would also leave you with a larger number then 8 bit so you would not be able to write straight to the port as you are doing now. You could however use a LCD to show the result.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel