Paso 4: Programar en C languagemy lo
#include
#include
#include "24LC256.h"
#include
/*----------------------------------------------------
asignación del puerto y poco para LCD ***
----------------------------------------------------*/
#define TH0RELOAD_VALUE 0X3c
#define TL0RELOAD_VALUE 0Xb0
#define wheel_diameter 5
#define cierto 1
#define LED_DSP P2 / / exhibición de LED (LED de 7 segmentos)
typedef unsigned char bit_8;
g_byCountOf50ms de bit_8;
unsigned char num_led [16] el código =
{0x3F, 0 x 06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0x07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0 x 39, 0x5E, 0x79, //A,b,C,d,E
0x71};
unsigned char sensor_variable, velocidad, switch_inc_variable;
unsigned char waiting_time_chargevariable, charge_pulse;
unsigned char EData;
Float distance_temp;
unsigned int distancia = 0, distance_temp2 = 0, distance_temp1;
unsigned int waiting_time_temp, waiting_time, caso, charge_variable = 8;
poco distance_inc_flag, switch_mode_flag, change_status_flag, device1_flag, device2_flag, device3_flag, device4_flag, device5_flag, device6_flag, device7_flag, device8_flag;
poco run_bit;
código bit_8 * [val] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; conjunto de dígitos
código unsigned char * route1 [] = {"MP nagar", "MP nagar", "MP nagar", "MP nagar", "MP nagar"};
código unsigned char * route2 [] = {"5-no hay Stop", "Colonia jerárquico", "T T Nagar", "Ayodhya", "Piplani"};
código unsigned char * carga [] = {"Max Charge = 50Rs","Max Charge = 60Rs","Max Charge = 200Rs","Max Charge = 200Rs","Max Charge = 60Rs"};
código unsigned char * distance1 [] = {"MaxDistance = 15 km","MaxDistance = 25 km","MaxDistance = 30 km","MaxDistance = 35 km","MaxDistance = 13 km"};
SBIT rs = P0 ^ 0; Registro seleccione puerto 3.5
SBIT rw = P0 ^ 1; lectura y escritura es puerto 3.4
SBIT at = P0 ^ 2; activar es puerto 3.3
SBIT d7 = P1 ^ 7; Bandera de ocupado es puerto 1.7
SBIT DSP1 = P0 ^ 3; DSP1 enable (activo bajo nivel)
SBIT DSP2 = P0 ^ 4; Activar DSP2 (Active Low level)
SBIT DSP3 = P0 ^ 5; DSP3 enable (activo bajo nivel)
SBIT Dot_Point = P2 ^ 7;
SBIT route_selection = P0 ^ 7;
ejecutar de SBIT = P0 ^ 6;
SBIT prepagada = P0 ^ 5;
void command(bit_8);
void data_in(bit_8*);
void initlcd(void);
void display_numeric (bit_8);
void display_int(unsigned int);
retardo de vacío (unsigned int);
void display_led (int num, int dly);
void external0 () interrupción 0
{
sensor_variable ++;
charge_pulse ++;
waiting_time_temp = 0;
EX0 = 0;
}
interrupción de vacío timer1 () 3
{
}
interrupción de timer0 nula () 1
{
TH0 = TH0RELOAD_VALUE;
TL0 = TL0RELOAD_VALUE;
g_byCountOf50ms ++;
if(charge_pulse==10)
{
charge_variable = charge_variable + 2;
charge_pulse = 0;
}
Si (g_byCountOf50ms > = 20)
{
que significa 1 segundo (ms 50 X 20) es más
g_byCountOf50ms = 0;
cálculo de la distancia temporal de 1 segundo
distance_temp = distance_temp1 = sensor_variable * wheel_diameter;
calcular la velocidad en 1 segundo
velocidad = distance_temp/0.0166;
distance_temp2 = distance_temp2 + distance_temp1;
calcular el distace total de la distance_temp1
distancia = distance_temp1 + distancia;
waiting_time_temp ++;
sensor_variable = 0;
if(distance_fare)
if(waiting_time_temp>20)
{
waiting_time ++;
waiting_time_chargevariable ++;
}
if(waiting_time_chargevariable>10)
{
caso ++;
waiting_time_chargevariable = 0;
}
}
}
void main()
{
unsigned char route_selection_variable;
route_selection = 1;
ejecutar = 1;
prepago = 1;
initlcd();
Command(0x80);
data_in ("AutomatedDigital");
Command(0xc0);
data_in ("*** Taxi metro ***");
Command(0x90);
data_in ("Pres * a la lista");
Command(0xD0);
data_in ("Pres # a ejecutar");
TMOD = 0 X 01;
TCON = 0X11;
IE = 0X83;
while(1)
{
if(route_selection==0)
{
comando (0 x 80);
data_in (route1[route_selection_variable]);
comando (0xc0);
data_in (route2[route_selection_variable]);
comando (0x90);
data_in (charge[route_selection_variable]);
comando (0xd0);
data_in (distance1[route_selection_variable]);
route_selection_variable ++;
Delay (100);
if(route_selection_variable==4)
{
route_selection_variable = 0;
}
}
if(Run==0)
{
run_bit = 1;
initlcd();
IE = 0X83;
}
if(Prepaid==0)
{
initlcd();
comando (0 x 80);
data_in "(modo de prepago");
comando (0xc0);
data_in ("ID =");
DelayMs(50);
EData = ReadBYTE(0x00); colacionar
comando (0xcb);
display_int(EData);
comando (0x90);
data_in ("Secret ID =");
EData = ReadBYTE(0x01); colacionar
comando (0x9b);
display_int(EData);
}
if(run_bit==1)
{
EX0 = 1;
comando (0 x 80);
data_in ("Trav Dist =");
comando (0x8a);
display_int (distancia);
comando (0xc0);
data_in ("velocidad =");
comando (0xc6);
display_int (velocidad);
comando (0xcb);
data_in ("km/h");
comando (0x90);
data_in ("tiempo de espera =");
comando (0x9a);
display_int (waiting_time);
comando (0xd0);
data_in ("esperar grcs =");
comando (0xda);
display_int(chargevariable);
display_led(charge_variable,150);
display_led(waiting_time,150);
}
retrasar (1000);
}
}
/*--------------------------
inicializar el LCD ***
--------------------------*/
void initlcd()
{
Command(56);
Command(0x01);
Command(0x02);
Command(12);
}
/*----------------------------
comprobación de la bandera de ocupado ***
----------------------------*/
void busy()
{
D7 = 1;
RS = 0;
RW = 1;
while(D7!=0)
{
at = 0;
at = 1;
}
}
/*-------------------------
Enviar comando al LCD ***
-------------------------*/
void command(bit_8 val)
{
Busy();
P1 = val;
RS = 0;
RW = 0;
at = 1;
at = 0;
}
/*--------------------------
introducción de datos al LCD ***
--------------------------*/
void data_in(bit_8 *string)
{
bit_8 i;
Busy();
for(i=0;String[i]!='\0';i++)
{
P1 = cadena [i];
RS = 1;
RW = 0;
at = 1;
at = 0;
}
}
void display_int(unsigned int i)
{
unsigned char ten_thousands, miles, cientos, decenas, unos;
ten_thousands = i / 10000;
data_in(Val[ten_thousands]);
i = i % 10000;
miles = i / 1000;
data_in(Val[Thousands]);
i = i % 1000;
cientos = i / 100;
data_in(Val[Hundreds]);
i = i % 100;
decenas = i / 10;
data_in(Val[TENS]);
unos = i % 10;
data_in(Val[ones]);
}
retardo de vacío (unsigned int k)
{
unsigned int i, j;
para (i = 0; i < = k; i ++)
para (j = 0; j < = 100; j ++);
}
void display_led (int num, int dly) {}
int i, n1, n2, n3;
N1 = (int)(num/100); Operador de división (53/10 = 5)
Num = (int) (num % 100);
N2 =(int) (num/10);
N2 = (int)(num%10); Operador de módulos (53% 10 = 3)
para (i = 0; i DSP1 = 0; / / DSP1 habilitar active
DSP2 = 1;
DSP3 = 0;
LED_DSP = num_led [n3];
Delay(1);
DSP2 = 0; DSP2 enable activa
DSP1 = 1;
DSP3 = 0;
LED_DSP = num_led [n2];
Delay(1);
DSP2 = 0; DSP2 enable activa
DSP1 = 0;
DSP3 = 1;
LED_DSP = num_led [1];
Delay(1);
}
}
/*
void display_led (int num, int dly) {}
int i, n1, n2, n3;
N1 = (int)(num/100); Operador de división (321/100 = 3)
Num = (int)(num%100); Operador de módulos (321% 100 = 21)
N2 = (int)(num/10); Operador de división (21/10 = 2)
N3 = (int)(num%10);
para (i = 0; i DSP1 = 1; / / DSP1 habilitar active
DSP2 = 0;
DSP3 = 0;
LED_DSP = num_led [n3];
Delay(1);
DSP2 = 1; DSP2 enable activa
DSP1 = 0;
DSP3 = 0;
LED_DSP = num_led [n2];
Delay(1);
DSP3 = 1; DSP2 enable activa
DSP1 = 0;
DSP2 = 0;
LED_DSP = num_led [n1];
Delay(1);
}
} */
#include
#include
#include "24LC256.h"
#include
/*----------------------------------------------------
asignación del puerto y poco para LCD ***
----------------------------------------------------*/
#define TH0RELOAD_VALUE 0X3c
#define TL0RELOAD_VALUE 0Xb0
#define wheel_diameter 5
#define cierto 1
#define LED_DSP P2 / / exhibición de LED (LED de 7 segmentos)
typedef unsigned char bit_8;
g_byCountOf50ms de bit_8;
unsigned char num_led [16] el código =
{0x3F, 0 x 06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0x07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0 x 39, 0x5E, 0x79, //A,b,C,d,E
0x71};
unsigned char sensor_variable, velocidad, switch_inc_variable;
unsigned char waiting_time_chargevariable, charge_pulse;
unsigned char EData;
Float distance_temp;
unsigned int distancia = 0, distance_temp2 = 0, distance_temp1;
unsigned int waiting_time_temp, waiting_time, caso, charge_variable = 8;
poco distance_inc_flag, switch_mode_flag, change_status_flag, device1_flag, device2_flag, device3_flag, device4_flag, device5_flag, device6_flag, device7_flag, device8_flag;
poco run_bit;
código bit_8 * [val] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; conjunto de dígitos
código unsigned char * route1 [] = {"MP nagar", "MP nagar", "MP nagar", "MP nagar", "MP nagar"};
código unsigned char * route2 [] = {"5-no hay Stop", "Colonia jerárquico", "T T Nagar", "Ayodhya", "Piplani"};
código unsigned char * carga [] = {"Max Charge = 50Rs","Max Charge = 60Rs","Max Charge = 200Rs","Max Charge = 200Rs","Max Charge = 60Rs"};
código unsigned char * distance1 [] = {"MaxDistance = 15 km","MaxDistance = 25 km","MaxDistance = 30 km","MaxDistance = 35 km","MaxDistance = 13 km"};
SBIT rs = P0 ^ 0; Registro seleccione puerto 3.5
SBIT rw = P0 ^ 1; lectura y escritura es puerto 3.4
SBIT at = P0 ^ 2; activar es puerto 3.3
SBIT d7 = P1 ^ 7; Bandera de ocupado es puerto 1.7
SBIT DSP1 = P0 ^ 3; DSP1 enable (activo bajo nivel)
SBIT DSP2 = P0 ^ 4; Activar DSP2 (Active Low level)
SBIT DSP3 = P0 ^ 5; DSP3 enable (activo bajo nivel)
SBIT Dot_Point = P2 ^ 7;
SBIT route_selection = P0 ^ 7;
ejecutar de SBIT = P0 ^ 6;
SBIT prepagada = P0 ^ 5;
void command(bit_8);
void data_in(bit_8*);
void initlcd(void);
void display_numeric (bit_8);
void display_int(unsigned int);
retardo de vacío (unsigned int);
void display_led (int num, int dly);
void external0 () interrupción 0
{
sensor_variable ++;
charge_pulse ++;
waiting_time_temp = 0;
EX0 = 0;
}
interrupción de vacío timer1 () 3
{
}
interrupción de timer0 nula () 1
{
TH0 = TH0RELOAD_VALUE;
TL0 = TL0RELOAD_VALUE;
g_byCountOf50ms ++;
if(charge_pulse==10)
{
charge_variable = charge_variable + 2;
charge_pulse = 0;
}
Si (g_byCountOf50ms > = 20)
{
que significa 1 segundo (ms 50 X 20) es más
g_byCountOf50ms = 0;
cálculo de la distancia temporal de 1 segundo
distance_temp = distance_temp1 = sensor_variable * wheel_diameter;
calcular la velocidad en 1 segundo
velocidad = distance_temp/0.0166;
distance_temp2 = distance_temp2 + distance_temp1;
calcular el distace total de la distance_temp1
distancia = distance_temp1 + distancia;
waiting_time_temp ++;
sensor_variable = 0;
if(distance_fare)
if(waiting_time_temp>20)
{
waiting_time ++;
waiting_time_chargevariable ++;
}
if(waiting_time_chargevariable>10)
{
caso ++;
waiting_time_chargevariable = 0;
}
}
}
void main()
{
unsigned char route_selection_variable;
route_selection = 1;
ejecutar = 1;
prepago = 1;
initlcd();
Command(0x80);
data_in ("AutomatedDigital");
Command(0xc0);
data_in ("*** Taxi metro ***");
Command(0x90);
data_in ("Pres * a la lista");
Command(0xD0);
data_in ("Pres # a ejecutar");
TMOD = 0 X 01;
TCON = 0X11;
IE = 0X83;
while(1)
{
if(route_selection==0)
{
comando (0 x 80);
data_in (route1[route_selection_variable]);
comando (0xc0);
data_in (route2[route_selection_variable]);
comando (0x90);
data_in (charge[route_selection_variable]);
comando (0xd0);
data_in (distance1[route_selection_variable]);
route_selection_variable ++;
Delay (100);
if(route_selection_variable==4)
{
route_selection_variable = 0;
}
}
if(Run==0)
{
run_bit = 1;
initlcd();
IE = 0X83;
}
if(Prepaid==0)
{
initlcd();
comando (0 x 80);
data_in "(modo de prepago");
comando (0xc0);
data_in ("ID =");
DelayMs(50);
EData = ReadBYTE(0x00); colacionar
comando (0xcb);
display_int(EData);
comando (0x90);
data_in ("Secret ID =");
EData = ReadBYTE(0x01); colacionar
comando (0x9b);
display_int(EData);
}
if(run_bit==1)
{
EX0 = 1;
comando (0 x 80);
data_in ("Trav Dist =");
comando (0x8a);
display_int (distancia);
comando (0xc0);
data_in ("velocidad =");
comando (0xc6);
display_int (velocidad);
comando (0xcb);
data_in ("km/h");
comando (0x90);
data_in ("tiempo de espera =");
comando (0x9a);
display_int (waiting_time);
comando (0xd0);
data_in ("esperar grcs =");
comando (0xda);
display_int(chargevariable);
display_led(charge_variable,150);
display_led(waiting_time,150);
}
retrasar (1000);
}
}
/*--------------------------
inicializar el LCD ***
--------------------------*/
void initlcd()
{
Command(56);
Command(0x01);
Command(0x02);
Command(12);
}
/*----------------------------
comprobación de la bandera de ocupado ***
----------------------------*/
void busy()
{
D7 = 1;
RS = 0;
RW = 1;
while(D7!=0)
{
at = 0;
at = 1;
}
}
/*-------------------------
Enviar comando al LCD ***
-------------------------*/
void command(bit_8 val)
{
Busy();
P1 = val;
RS = 0;
RW = 0;
at = 1;
at = 0;
}
/*--------------------------
introducción de datos al LCD ***
--------------------------*/
void data_in(bit_8 *string)
{
bit_8 i;
Busy();
for(i=0;String[i]!='\0';i++)
{
P1 = cadena [i];
RS = 1;
RW = 0;
at = 1;
at = 0;
}
}
void display_int(unsigned int i)
{
unsigned char ten_thousands, miles, cientos, decenas, unos;
ten_thousands = i / 10000;
data_in(Val[ten_thousands]);
i = i % 10000;
miles = i / 1000;
data_in(Val[Thousands]);
i = i % 1000;
cientos = i / 100;
data_in(Val[Hundreds]);
i = i % 100;
decenas = i / 10;
data_in(Val[TENS]);
unos = i % 10;
data_in(Val[ones]);
}
retardo de vacío (unsigned int k)
{
unsigned int i, j;
para (i = 0; i < = k; i ++)
para (j = 0; j < = 100; j ++);
}
void display_led (int num, int dly) {}
int i, n1, n2, n3;
N1 = (int)(num/100); Operador de división (53/10 = 5)
Num = (int) (num % 100);
N2 =(int) (num/10);
N2 = (int)(num%10); Operador de módulos (53% 10 = 3)
para (i = 0; i DSP1 = 0; / / DSP1 habilitar active
DSP2 = 1;
DSP3 = 0;
LED_DSP = num_led [n3];
Delay(1);
DSP2 = 0; DSP2 enable activa
DSP1 = 1;
DSP3 = 0;
LED_DSP = num_led [n2];
Delay(1);
DSP2 = 0; DSP2 enable activa
DSP1 = 0;
DSP3 = 1;
LED_DSP = num_led [1];
Delay(1);
}
}
/*
void display_led (int num, int dly) {}
int i, n1, n2, n3;
N1 = (int)(num/100); Operador de división (321/100 = 3)
Num = (int)(num%100); Operador de módulos (321% 100 = 21)
N2 = (int)(num/10); Operador de división (21/10 = 2)
N3 = (int)(num%10);
para (i = 0; i DSP1 = 1; / / DSP1 habilitar active
DSP2 = 0;
DSP3 = 0;
LED_DSP = num_led [n3];
Delay(1);
DSP2 = 1; DSP2 enable activa
DSP1 = 0;
DSP3 = 0;
LED_DSP = num_led [n2];
Delay(1);
DSP3 = 1; DSP2 enable activa
DSP1 = 0;
DSP2 = 0;
LED_DSP = num_led [n1];
Delay(1);
}
} */