use of registers ?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
jack
Posts: 10
Joined: Sat Jun 16, 2007 8:00 am

use of registers ?

Post by jack »

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

jack
Posts: 10
Joined: Sat Jun 16, 2007 8:00 am

Post by jack »

i find the way for assembleur

for exemple
asm clrf _tmr0


just put the "_" before the register

jack
Posts: 10
Joined: Sat Jun 16, 2007 8:00 am

Post by jack »

prat i am

i wrote trm0 instead of tmr0

you know dyxlexie ?


the code c
tmr0 = 0; works !

and now how read the tmr0 and put it in a variable ?

jack
Posts: 10
Joined: Sat Jun 16, 2007 8:00 am

Post by jack »

in flowcode add a variable MYVAR (byte)

code c:
FCV_MYVAR = tmr0;

User avatar
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:

Post by Benj »

Hello Jack

Thanks for posting your progress. Seems like you have it sorted now.

jack
Posts: 10
Joined: Sat Jun 16, 2007 8:00 am

Post by jack »

Image

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
simulatio does not work but the program yes


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 !

User avatar
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:

Post by Benj »

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.

jack
Posts: 10
Joined: Sat Jun 16, 2007 8:00 am

Post by jack »

thank Benji for your reply

i use timer0 as a counter and i want it count the low to hight transition on the pin T0CK1

i find the solution
when the prescaler rate select bits :ps2 ps1 ps0 (OPTION_REG bits 2,1,0) are set to 0, the TMR0 rate is 1:2


now i wil try the tmr1 !

Post Reply