Microcontroller › 8051 › Problem with multisim timer program
- This topic has 0 replies, 1 voice, and was last updated 12 years, 7 months ago by john.
-
AuthorPosts
-
March 9, 2012 at 4:58 pm #1588johnParticipant
Hello all,
I am currently having trouble building this timer counter program in multisim. It seems to compile okm in keil. however in multisim
I get two “constant expression required” error messages.Any help would be greatly appreciated as this is holding up the rest of my project as i need to use an interrupt to compare the two values (frequencies) in the timers.
Thanks for any input,
MY SAMPLE
#include<htc.h>
#define TRUE 1
#define FALSE 0bit LED=P1^2;
void delay(void);//50us delay;
static void delay1(void){//set up for 1ms delay
char c;
for(c=0;c<20;c++){
delay();
}
}bit On_Off=P1^0;//On-Off switch on P1^0//(Starts device)
//function to see if switched is pressed
bit SwitchOn_Off(void);//50ms debounce function
void debounce (void);//function to count the pulses received on the timer input pins(T0 and T1)
void Pulsecount(void);
void delay(void);//50us delay;void main (void){
while (TRUE){
if (SwitchOn_Off()==TRUE){
LED=0;Pulsecount();//initiate count
}
else{}//do nothing}
}bit SwitchOn_Off(void){
if(On_Off==FALSE){//If switched is closed(0)
debounce();//carry out switch debounce(delay Procedure)
return TRUE;//Returns TRUE to allow operation to carry on
}
return FALSE;//function returns a FALSE
}void debounce (void){
TL0=0xb0;
TH0=0x3c;
TMOD=0x01;
TR0=1;
TF0=0;
/*sets timer0 as interval timer and loads the decimal value
15536 in to it;;leading to it being incremeneted 50000 times
before it overflows;;ie TF=1(50ms)*/
while (TF0==FALSE){}
TR0=FALSE;
TF0=FALSE;
}void Pulsecount(void){
while(TRUE)
T0=1;//set T0 as input pin(therefore increments Timer0 as pulse goes from low to high
T1=1;//set T1 as input pin(therefore increments Timer1 as pulse goes from low to highTMOD=0x55;//sets Timers in 16bit interval timer mode
//clear any values in timers
TH1=0;
TL1=0;
TH0=0;
TL0=0;TR1=TRUE;//start timer1
TR0=TRUE;//start timer0
delay1();
TR1=FALSE;
TR0=FALSE;}
void delay (void){
char c;
for(c=0;c<16;c++);//50us delay
}
-
AuthorPosts
- You must be logged in to reply to this topic.