I'm new to micro c . Need to turn Timer1 on pic16F877A after pressed a switch 1 and then turn it off when pressed switch 2, then displaying the period of the time on LCD. Plz help me someone...it is urgent...
I attached proteus simulation picture as well as micro c code that i tried... but i don't no whether it is correct...
// LCD module connections
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;// End LCD module connectionsunsigned cnt;// This is the counter variable which will extend desired periodchar abc[7];int clk2;void InitTimer0(){
OPTION_REG =0x84;// Prescaler 256
TMR0 =100;
INTCON =0xA0;}void Interrupt(){// Occurs every 1msif(TMR0IF_bit){
cnt++;// Increment counter, this is the tweak we added in original Timer Calculator code
TMR0IF_bit =0;// Clear TMR0IF
TMR0 =100;// Prepare for next interrupt}}void display(){
Lcd_Cmd(_LCD_CLEAR);// Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);// Cursor off
IntToStr(clk2, abc);
Lcd_Out(1,1,abc);// Write text'Hello World' in first row}void main(){
InitTimer0();// Initialize Timer0
TRISD.F1=0;//Configure 1st bit of PORTD as output
PORTD.F1=0;//LED OFF
TRISD.F0=1;//Configure 1st bit of PORTD as input
TRISD.F2=1;//Configure 1st bit of PORTD as input
cnt =0;// Initialize cnt
Lcd_Init();// Initialize LCD
Lcd_Cmd(_LCD_CLEAR);// Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);// Cursor off
Lcd_Out(1,1,"Hello");// Write text'Hello World' in first rowdo{if(PORTD.F0==0)//If the switch is pressed{
Delay_ms(100);//Switch Debounceif(PORTD.F0==0)//If the switch is still pressed{
cnt =0;
PORTD.F1=1;}}if(PORTD.F2==0)//If the switch is pressed{
Delay_ms(100);//Switch Debounceif(PORTD.F2==0)//If the switch is still pressed
PORTD.F1=1;
clk2 = cnt;
Display();}}while(1);}
What is the problem with your setup? if I will suggest implement an interrupt timer that Blick the led at a fixed time interval. Then the other part can follow.
Thank you very mush for responses...I want to swtich on timer when pressed push button 1 and stop the timer when presse push button 2.then period of time display on lcd...PLZ help me...
I want to swtich on timer when pressed push button 1 and stop when pressed push button 2 and display time period one diplay...thanks for responses...
No. But those informations he needs to provide to everybody who wants to write code for him.
And even he needs those informations if he wants to wrtie it on his own.
***
You said "a 100ms timer". Maybe this is the easiest solution. But who knows?.
If he wants to build a stop watch, then maybe he wants a better resolution.
But maybe he wants to measure the time from winter to summer....
***
Maybe he wants to measure the reaction time of a relay..
For a measurement tool the measured value needs to be reliable and accurate..
if you want a 10ms resolution (then a 1ms accuracy is not possible) then:
* set up timer for interrupt 10ms.
Code:
declare run as bool = 0
on every timer tick:
* if START = pressed then RUN = 1
* if STOP = pressed then
if RUN = 1 then
RUN = 0
display COUNTER
COUNTER = 0
* if RUN = 1 then counter = counter +1
end of interrupt
main loop: nothing to do.
Try to program this.
Test it.
Then give us your program and the results of our test run.