ana_cont
Junior Member level 2
Code:
const wh_length=11;
const pulse=36;
const meter_pulse=(100/wh_length)*pulse;
int meter=0;
char speedshow[30];
char RPMshow[30];
char distanceshow[30];
int count_puls=0;
int speed ;
int rpm=0;
void Interrupcion() iv 0x0004 ics ICS_AUTO
{
if (INTF_bit==1)
{
rpm = (1000/count_puls) * 60;
speed = meter/count_puls;
}
INTF_bit=0;
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0 = 6;
count_puls++;
}
}
void InitTimer0(){
OPTION_REG = 0x81;
TMR0 = 6;
INTCON = 0xA0;
}
void main()
{
UART1_Init(115200);
trisb.b0=1;
trisd=0;
InitTimer0();
t1con=0;
T1CKPS1_bit=0;
T1CKPS0_bit=0;
INTEDG_bit=1;
INTF_bit=0;
INTE_bit=1;
GIE_bit=1;
while (1)
{
if (count_puls>=meter_pulse){
meter++;
count_puls=0;
}
sprinti(speedshow,"n0.val=%d",speed);
UART1_Write_Text(speedshow);
UART1_Write(0XFF);
UART1_Write(0XFF);
UART1_Write(0XFF);
sprinti(RPMshow,"n1.val=%d",RPM);
UART1_Write_Text(RPMshow);
UART1_Write(0XFF);
UART1_Write(0XFF);
UART1_Write(0XFF);
sprinti(distanceshow,"n2.val=%d",meter);
UART1_Write_Text(distanceshow);
UART1_Write(0XFF);
UART1_Write(0XFF);
UART1_Write(0XFF);
}
}
Last edited by a moderator: