I'm trying to understand how this programm work can you help me
it's about a tchometer contact less it count the speed with PIC18F2550
it's about a tchometer contact less it count the speed with PIC18F2550
Rich (BB code):
sbit IR_Tx at RA3_bit;
// Define Messages
char message1[] = "2014TACHY.V3.COM";
char *RPM = "00000 RPM";
//================================================
void Display_RPM(unsigned long num)
{
RPM[0] = num/10000 + 48;
RPM[1] = (num/1000)%10 + 48;
RPM[2] = (num/100)%10 + 48;
RPM[3] = (num/10)%10 + 48;
RPM[4] = num%10 + 48;
Lcd_Out(2,4,RPM);
//UART_Write_Text(RPM);
}
//================================================
void main()
{
CMCON = 0x07; // Disable comparators
ADCON1 = 0x0F; // Disable Analog functions
//TRISC = 0x00;
TRISC = 0x80; // Port C output except RC7 RX
TRISB = 0x00;
PORTA = 0x00;
TRISA = 0b00010000;
T0CON = 0b01101000; // TMR0 as 16-bit counter
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,message1); // Write message1 in 1st row
//----
UART1_Init(9600); // initialize UART1 module
Delay_ms(100);
//----
do
{
T0CON.TMR0ON = 1;
TMR0L = 0;
TMR0H = 0;
IR_Tx = 1;
Delay_ms(1000); // Wait for 1 sec
IR_Tx = 0;
T0CON.TMR0ON = 0; // Stop the timer
RPM_Value = (256*TMR0H + TMR0L)*60;
Display_RPM(RPM_Value);
//----
LongToStr(RPM_Value, txt);
UART_Write_Text("N");
Delay_ms(10); // Wait for 1 sec
//UART_Write_Text("2014TACHY.V3.COM");
UART_Write_Text(txt);
//----
} while(1); // Infinite Loop
}
Last edited by a moderator: