0% found this document useful (0 votes)
20 views

Code

TMOD.T1_GATE = 0; / / Clear this flag to enable Timer1 whenever TR1 bit is. If ((p1_0==1) && (j==0)) j=1; v=0; TR1=1; enable the timer while (j=0; v; v is a counter and after this formula is implemented I t will store the speed lcd_out (1,7,
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Code

TMOD.T1_GATE = 0; / / Clear this flag to enable Timer1 whenever TR1 bit is. If ((p1_0==1) && (j==0)) j=1; v=0; TR1=1; enable the timer while (j=0; v; v is a counter and after this formula is implemented I t will store the speed lcd_out (1,7,
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// lcd module pin configuration sbit LCD_RS at P2.B0; sbit LCD_EN at P2.B1; sbit LCD_D7 at P2.

B5; sbit LCD_D6 at P2.B4; sbit LCD_D5 at P2.B3; sbit LCD_D4 at P2.B2; int v=0; void Timer1InterruptHandler() org 0x1B{ EA = 0; p0=~p0; v++; EA = 1; TR1 = 1; } // Set global interrupt enable flag // Run Timer1 // Clear global interrupt enable flag

void main() { int i; int k=0; int j=0; char arr[7]; int m; m=Eeprom_Read (2); // read the distance moved by the car by now // start: P0 = 0; // Initialize PORT0 TF1 = 0; ET1 = 1; EA = 1; set. TMOD.T1_CT systam clock. TMOD.T1_M1 TMOD.T1_M0 TR1 = 0; TH1 = 0x00; TL1 = 0x00; = 0; // Set Timer operation: Timer1 counts the divided-down = 0; // M1_M0 = 01 = 1; => Mode 1(16-bit Timer/Counter) // Ensure that Timer1 interrupt flag is cleared // Enable Timer1 interrupt // Set global interrupt enable

TMOD.T1_GATE = 0; // Clear this flag to enable Timer1 whenever TR1 bit is

// Turn off Timer1 // Set Timer1 high byte // Set Timer1 low byte

Lcd_Init(); // initialize the lcd Lcd_Cmd(LCD_CLEAR); // clear the lcd Lcd_Cmd(LCD_CURSOR_OFF); // remove the cursor lcd_out (1,1,"Speed:"); lcd_out (1,13,"K/hr"); Lcd_Out (2,1,"Odo:"); Lcd_out (2,13,"Km");

while (1) { if ((p1_0==1) && (j==0)) // when the sensor is cut for the first time { j=1; v=0; TR1=1; // enable the timer while (p1_0==1); // wait till the sensor is being cut } if ((p1_0==1) && (j==1)) // when the senor is cut for the second time { TR1=0;// disable the timer v=200/v; // v is a counter and after this formula is implemented i t will store the speed inttostr (v,arr); // print the speed lcd_out (1,7,arr); m++; // increment the reading of the odometer Eeprom_write (2,m); // store it in the eeprom j=0; while (p1_0==1); // wait till the second sensor is being cut } if (v>200) // if the wheel is stopped { v=0; inttostr (v,arr); // print the speed as 0 lcd_out (1,7,arr); } inttostr (m,arr);// print the reading of the odometer on the lcd lcd_out (2,7,arr); }

You might also like