chanidu
Newbie level 4
- Joined
- Mar 21, 2016
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 75
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...
I attached proteus simulation picture as well as micro c code that i tried... but i don't no whether it is correct...
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 // 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 connections unsigned cnt; // This is the counter variable which will extend desired period char abc[7]; int clk2; void InitTimer0(){ OPTION_REG = 0x84; // Prescaler 256 TMR0 = 100; INTCON = 0xA0; } void Interrupt(){ // Occurs every 1ms if (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 row do { if(PORTD.F0 == 0) //If the switch is pressed { Delay_ms(100); //Switch Debounce if(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 Debounce if(PORTD.F2 == 0)//If the switch is still pressed PORTD.F1 = 1; clk2 = cnt; Display(); } } while(1); }
Last edited by a moderator: