as i understand i wrote this code and i know its not correct and have some problem
can any one correct it please
---------------------------------------------------------------------------
(( code in file attachment ))
pic16f877A --- result show in nextion lcd ( uart )
target of this code to show in nextion lcd speed ( km/h) and RPM and distance
important note ( wheel diameter 11 cm ) and one round = 36 puls
i use pin B0 ( int ) to count puls
and i used internal timer to give me 1 ms time
--------------------------------------------------------------------------------------
code - mikroc
----------------------------------------
Mod edit: code=C tag for better formatting - Welcome to AAC!
can any one correct it please
---------------------------------------------------------------------------
(( code in file attachment ))
pic16f877A --- result show in nextion lcd ( uart )
target of this code to show in nextion lcd speed ( km/h) and RPM and distance
important note ( wheel diameter 11 cm ) and one round = 36 puls
i use pin B0 ( int ) to count puls
and i used internal timer to give me 1 ms time
--------------------------------------------------------------------------------------
code - mikroc
----------------------------------------
C:
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);
}
}
Attachments
-
85.6 KB Views: 6
Last edited by a moderator: