Étape 4: Programmer en C languagemy lo
#include
#include
#include « 24LC256.h »
#include
/*----------------------------------------------------
affectation de port et peu pour LCD ***
----------------------------------------------------*/
#define TH0RELOAD_VALUE 0X3c
#define TL0RELOAD_VALUE 0Xb0
#define wheel_diameter 5
#define vrai 1
#define LED_DSP P2 / / affichage LED (LED 7 segments)
typedef unsigned char bit_8 ;
bit_8 g_byCountOf50ms ;
unsigned char num_led [16] le code =
{0x3F, 0 x 06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0 x 07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0 x 39, 0x5E, 0x79, //A,b,C,d,E
0x71} ;
unsigned char sensor_variable, vitesse, switch_inc_variable ;
unsigned char waiting_time_chargevariable, charge_pulse ;
unsigned char EData ;
float distance_temp ;
unsigned int distance = 0, distance_temp2 = 0, distance_temp1 ;
unsigned int waiting_time_temp, waiting_time, chargevariable, charge_variable = 8 ;
bit 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 ;
bit run_bit ;
code bit_8 * [val] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"} ; Tableau de chiffres
code unsigned char * route1 [] = {"nagar MP", "MP nagar", "MP nagar", "MP nagar", "MP nagar"} ;
code unsigned char * route2 [] = {"5-No-Stop", "Arera Colony", "T T Nagar", "Ayodhya", "Piplani"} ;
code unsigned char * charger [] = {"Max Charge = 50Rs","Max Charge = 60Rs","Max Charge = 200Rs","Max Charge = 200Rs","Max Charge = 60Rs"} ;
code unsigned char * distance1 [] = {"MaxDistance = 15 km","MaxDistance = 25 km","MaxDistance = 30 km","MaxDistance = 35 km","MaxDistance = 13 km"} ;
sbit rs = P0 ^ 0 ; s’inscrire à select est port 3.5
sbit rw = P0 ^ 1 ; lecture/écriture est port 3.4
sbit fr = P0 ^ 2 ; Enable est port 3.3
sbit d7 = P1 ^ 7 ; Pavillon occupé est port 1.7
sbit DSP1 = P0 ^ 3 ; Enable dSP1 (Active Low level)
sbit DSP2 = P0 ^ 4 ; DSP2 enable (Active Low level)
sbit DSP3 = P0 ^ 5 ; Dsp3 enable (Active Low level)
sbit Dot_Point = P2 ^ 7 ;
sbit route_selection = P0 ^ 7 ;
sbit exécuter = P0 ^ 6 ;
sbit prépayée = P0 ^ 5 ;
void command(bit_8) ;
void data_in(bit_8*) ;
void initlcd(void) ;
void display_numeric (bit_8) ;
void display_int(unsigned int) ;
Sub retard (unsigned int) ;
void display_led (int num, int dly) ;
Sub external0 () interruption 0
{
sensor_variable ++ ;
charge_pulse ++ ;
waiting_time_temp = 0 ;
EX0 = 0 ;
}
interrupt () de timer1 Sub 3
{
}
Sub timer0 () interruption 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)
{
Cela signifie que 1 seconde (50 ms X 20) est terminée
g_byCountOf50ms = 0 ;
calcul de la distance de temp pour 1 seconde
distance_temp = distance_temp1 = sensor_variable * wheel_diameter ;
calcul de la vitesse en 1 seconde
Vitesse = distance_temp/0,0166 ;
distance_temp2 = distance_temp2 + distance_temp1 ;
calculer la distace totale de la distance_temp1
distance = distance_temp1 + distance ;
waiting_time_temp ++ ;
sensor_variable = 0 ;
if(distance_fare)
if(waiting_time_temp>20)
{
waiting_time ++ ;
waiting_time_chargevariable ++ ;
}
if(waiting_time_chargevariable>10)
{
chargevariable ++ ;
waiting_time_chargevariable = 0 ;
}
}
}
Sub main()
{
unsigned char route_selection_variable ;
route_selection = 1 ;
courir = 1 ;
payé = 1 ;
initlcd() ;
Command(0x80) ;
impérativement ("AutomatedDigital") ;
Command(0xC0) ;
impérativement ("*** Taxi compteur ***") ;
Command(0X90) ;
impérativement (« Pres * To List ") ;
Command(0xD0) ;
impérativement (« Pres # à exécuter ") ;
TMOD = 0 X 01 ;
TCON = 0 X 11 ;
IE = 0 X 83 ;
while(1)
{
if(route_selection==0)
{
commande (0 x 80) ;
impérativement (route1[route_selection_variable]) ;
commande (0xc0) ;
impérativement (route2[route_selection_variable]) ;
commande (0x90) ;
impérativement (charge[route_selection_variable]) ;
commande (0xd0) ;
impérativement (distance1[route_selection_variable]) ;
route_selection_variable ++ ;
retard (100) ;
if(route_selection_variable==4)
{
route_selection_variable = 0 ;
}
}
if(Run==0)
{
run_bit = 1 ;
initlcd() ;
IE = 0 X 83 ;
}
if(Prepaid==0)
{
initlcd() ;
commande (0 x 80) ;
impérativement ("mode prépayé") ;
commande (0xc0) ;
impérativement ("CustomerID =") ;
DelayMs(50) ;
EData = ReadBYTE(0x00) ; collationné
commande (0xcb) ;
display_int(EData) ;
commande (0x90) ;
impérativement ("Secret ID =") ;
EData = ReadBYTE(0x01) ; collationné
commande (0x9b) ;
display_int(EData) ;
}
if(run_bit==1)
{
EX0 = 1 ;
commande (0 x 80) ;
impérativement (« Trav Dist = ") ;
commande (0x8a) ;
display_int (distance) ;
commande (0xc0) ;
impérativement ("vitesse =") ;
commande (0xc6) ;
display_int (vitesse) ;
commande (0xcb) ;
impérativement ("km/hr") ;
commande (0x90) ;
impérativement ("temps d’attente =") ;
commande (0x9a) ;
display_int (waiting_time) ;
commande (0xd0) ;
impérativement ("attendez CRG =") ;
commande (0xda) ;
display_int(chargevariable) ;
display_led(charge_variable,150) ;
display_led(waiting_time,150) ;
}
retarder (1000) ;
}
}
/*--------------------------
initialisation de l’écran LCD ***
--------------------------*/
Sub initlcd()
{
Command(56) ;
Command(0x01) ;
Command(0x02) ;
Command(12) ;
}
/*----------------------------
vérifier l’indicateur occupé ***
----------------------------*/
Sub busy()
{
D7 = 1 ;
RS = 0 ;
RW = 1 ;
while(D7!=0)
{
fr = 0 ;
fr = 1 ;
}
}
/*-------------------------
Envoyer la commande à LCD ***
-------------------------*/
Sub command(bit_8 val)
{
Busy() ;
P1 = val ;
RS = 0 ;
RW = 0 ;
fr = 1 ;
fr = 0 ;
}
/*--------------------------
saisie de données pour LCD ***
--------------------------*/
Sub data_in(bit_8 *string)
{
bit_8 i ;
Busy() ;
for(i=0;String[i]!='\0';i++)
{
P1 = string [i] ;
RS = 1 ;
RW = 0 ;
fr = 1 ;
fr = 0 ;
}
}
Sub display_int(unsigned int i)
{
des milliers, des centaines, dizaines, unsigned char ten_thousands, celles ;
ten_thousands = i / 10000 ;
data_in(Val[ten_thousands]) ;
J’ai j’ai = % 10000 ;
des milliers = i / 1000 ;
data_in(Val[Thousands]) ;
J’ai j’ai = % 1000 ;
des centaines = i / 100 ;
data_in(Val[HUNDREDS]) ;
J’ai j’ai = % 100 ;
des dizaines = i / 10 ;
data_in(Val[TENS]) ;
Ones = i % 10 ;
data_in(Val[Ones]) ;
}
Sub retard (unsigned int k)
{
unsigned int i, j ;
pour (i = 0; i < = k; i ++)
pour (j = 0; j < = 100; j ++) ;
}
void display_led (int num, int dly) {}
int i, n1, n2, n3 ;
N1 = (int)(num/100) ; Opérateur de division (53/10 = 5)
num = (int) (num % 100) ;
myEnumerator.Current N2 (num/10) ;
N2 = (int)(num%10) ; Opérateur de modules (53 % 10 = 3)
pour (i = 0; i DSP1 = 0; / / DSP1 activer active
DSP2 = 1 ;
DSP3 = 0 ;
LED_DSP = num_led [n3] ;
Delay(1) ;
DSP2 = 0 ; DSP2 activer active
DSP1 = 1 ;
DSP3 = 0 ;
LED_DSP = num_led [n2] ;
Delay(1) ;
DSP2 = 0 ; DSP2 activer active
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) ; Opérateur de division (321/100 = 3)
num = (int)(num%100) ; Opérateur de modules (321 % 100 = 21)
N2 = (int)(num/10) ; Opérateur de division (21/10 = 2)
N3 = (int)(num%10) ;
pour (i = 0; i DSP1 = 1; / / DSP1 activer active
DSP2 = 0 ;
DSP3 = 0 ;
LED_DSP = num_led [n3] ;
Delay(1) ;
DSP2 = 1 ; DSP2 activer active
DSP1 = 0 ;
DSP3 = 0 ;
LED_DSP = num_led [n2] ;
Delay(1) ;
DSP3 = 1 ; DSP2 activer active
DSP1 = 0 ;
DSP2 = 0 ;
LED_DSP = num_led [n1] ;
Delay(1) ;
}
} */
#include
#include
#include « 24LC256.h »
#include
/*----------------------------------------------------
affectation de port et peu pour LCD ***
----------------------------------------------------*/
#define TH0RELOAD_VALUE 0X3c
#define TL0RELOAD_VALUE 0Xb0
#define wheel_diameter 5
#define vrai 1
#define LED_DSP P2 / / affichage LED (LED 7 segments)
typedef unsigned char bit_8 ;
bit_8 g_byCountOf50ms ;
unsigned char num_led [16] le code =
{0x3F, 0 x 06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0 x 07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0 x 39, 0x5E, 0x79, //A,b,C,d,E
0x71} ;
unsigned char sensor_variable, vitesse, switch_inc_variable ;
unsigned char waiting_time_chargevariable, charge_pulse ;
unsigned char EData ;
float distance_temp ;
unsigned int distance = 0, distance_temp2 = 0, distance_temp1 ;
unsigned int waiting_time_temp, waiting_time, chargevariable, charge_variable = 8 ;
bit 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 ;
bit run_bit ;
code bit_8 * [val] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"} ; Tableau de chiffres
code unsigned char * route1 [] = {"nagar MP", "MP nagar", "MP nagar", "MP nagar", "MP nagar"} ;
code unsigned char * route2 [] = {"5-No-Stop", "Arera Colony", "T T Nagar", "Ayodhya", "Piplani"} ;
code unsigned char * charger [] = {"Max Charge = 50Rs","Max Charge = 60Rs","Max Charge = 200Rs","Max Charge = 200Rs","Max Charge = 60Rs"} ;
code unsigned char * distance1 [] = {"MaxDistance = 15 km","MaxDistance = 25 km","MaxDistance = 30 km","MaxDistance = 35 km","MaxDistance = 13 km"} ;
sbit rs = P0 ^ 0 ; s’inscrire à select est port 3.5
sbit rw = P0 ^ 1 ; lecture/écriture est port 3.4
sbit fr = P0 ^ 2 ; Enable est port 3.3
sbit d7 = P1 ^ 7 ; Pavillon occupé est port 1.7
sbit DSP1 = P0 ^ 3 ; Enable dSP1 (Active Low level)
sbit DSP2 = P0 ^ 4 ; DSP2 enable (Active Low level)
sbit DSP3 = P0 ^ 5 ; Dsp3 enable (Active Low level)
sbit Dot_Point = P2 ^ 7 ;
sbit route_selection = P0 ^ 7 ;
sbit exécuter = P0 ^ 6 ;
sbit prépayée = P0 ^ 5 ;
void command(bit_8) ;
void data_in(bit_8*) ;
void initlcd(void) ;
void display_numeric (bit_8) ;
void display_int(unsigned int) ;
Sub retard (unsigned int) ;
void display_led (int num, int dly) ;
Sub external0 () interruption 0
{
sensor_variable ++ ;
charge_pulse ++ ;
waiting_time_temp = 0 ;
EX0 = 0 ;
}
interrupt () de timer1 Sub 3
{
}
Sub timer0 () interruption 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)
{
Cela signifie que 1 seconde (50 ms X 20) est terminée
g_byCountOf50ms = 0 ;
calcul de la distance de temp pour 1 seconde
distance_temp = distance_temp1 = sensor_variable * wheel_diameter ;
calcul de la vitesse en 1 seconde
Vitesse = distance_temp/0,0166 ;
distance_temp2 = distance_temp2 + distance_temp1 ;
calculer la distace totale de la distance_temp1
distance = distance_temp1 + distance ;
waiting_time_temp ++ ;
sensor_variable = 0 ;
if(distance_fare)
if(waiting_time_temp>20)
{
waiting_time ++ ;
waiting_time_chargevariable ++ ;
}
if(waiting_time_chargevariable>10)
{
chargevariable ++ ;
waiting_time_chargevariable = 0 ;
}
}
}
Sub main()
{
unsigned char route_selection_variable ;
route_selection = 1 ;
courir = 1 ;
payé = 1 ;
initlcd() ;
Command(0x80) ;
impérativement ("AutomatedDigital") ;
Command(0xC0) ;
impérativement ("*** Taxi compteur ***") ;
Command(0X90) ;
impérativement (« Pres * To List ") ;
Command(0xD0) ;
impérativement (« Pres # à exécuter ") ;
TMOD = 0 X 01 ;
TCON = 0 X 11 ;
IE = 0 X 83 ;
while(1)
{
if(route_selection==0)
{
commande (0 x 80) ;
impérativement (route1[route_selection_variable]) ;
commande (0xc0) ;
impérativement (route2[route_selection_variable]) ;
commande (0x90) ;
impérativement (charge[route_selection_variable]) ;
commande (0xd0) ;
impérativement (distance1[route_selection_variable]) ;
route_selection_variable ++ ;
retard (100) ;
if(route_selection_variable==4)
{
route_selection_variable = 0 ;
}
}
if(Run==0)
{
run_bit = 1 ;
initlcd() ;
IE = 0 X 83 ;
}
if(Prepaid==0)
{
initlcd() ;
commande (0 x 80) ;
impérativement ("mode prépayé") ;
commande (0xc0) ;
impérativement ("CustomerID =") ;
DelayMs(50) ;
EData = ReadBYTE(0x00) ; collationné
commande (0xcb) ;
display_int(EData) ;
commande (0x90) ;
impérativement ("Secret ID =") ;
EData = ReadBYTE(0x01) ; collationné
commande (0x9b) ;
display_int(EData) ;
}
if(run_bit==1)
{
EX0 = 1 ;
commande (0 x 80) ;
impérativement (« Trav Dist = ") ;
commande (0x8a) ;
display_int (distance) ;
commande (0xc0) ;
impérativement ("vitesse =") ;
commande (0xc6) ;
display_int (vitesse) ;
commande (0xcb) ;
impérativement ("km/hr") ;
commande (0x90) ;
impérativement ("temps d’attente =") ;
commande (0x9a) ;
display_int (waiting_time) ;
commande (0xd0) ;
impérativement ("attendez CRG =") ;
commande (0xda) ;
display_int(chargevariable) ;
display_led(charge_variable,150) ;
display_led(waiting_time,150) ;
}
retarder (1000) ;
}
}
/*--------------------------
initialisation de l’écran LCD ***
--------------------------*/
Sub initlcd()
{
Command(56) ;
Command(0x01) ;
Command(0x02) ;
Command(12) ;
}
/*----------------------------
vérifier l’indicateur occupé ***
----------------------------*/
Sub busy()
{
D7 = 1 ;
RS = 0 ;
RW = 1 ;
while(D7!=0)
{
fr = 0 ;
fr = 1 ;
}
}
/*-------------------------
Envoyer la commande à LCD ***
-------------------------*/
Sub command(bit_8 val)
{
Busy() ;
P1 = val ;
RS = 0 ;
RW = 0 ;
fr = 1 ;
fr = 0 ;
}
/*--------------------------
saisie de données pour LCD ***
--------------------------*/
Sub data_in(bit_8 *string)
{
bit_8 i ;
Busy() ;
for(i=0;String[i]!='\0';i++)
{
P1 = string [i] ;
RS = 1 ;
RW = 0 ;
fr = 1 ;
fr = 0 ;
}
}
Sub display_int(unsigned int i)
{
des milliers, des centaines, dizaines, unsigned char ten_thousands, celles ;
ten_thousands = i / 10000 ;
data_in(Val[ten_thousands]) ;
J’ai j’ai = % 10000 ;
des milliers = i / 1000 ;
data_in(Val[Thousands]) ;
J’ai j’ai = % 1000 ;
des centaines = i / 100 ;
data_in(Val[HUNDREDS]) ;
J’ai j’ai = % 100 ;
des dizaines = i / 10 ;
data_in(Val[TENS]) ;
Ones = i % 10 ;
data_in(Val[Ones]) ;
}
Sub retard (unsigned int k)
{
unsigned int i, j ;
pour (i = 0; i < = k; i ++)
pour (j = 0; j < = 100; j ++) ;
}
void display_led (int num, int dly) {}
int i, n1, n2, n3 ;
N1 = (int)(num/100) ; Opérateur de division (53/10 = 5)
num = (int) (num % 100) ;
myEnumerator.Current N2 (num/10) ;
N2 = (int)(num%10) ; Opérateur de modules (53 % 10 = 3)
pour (i = 0; i DSP1 = 0; / / DSP1 activer active
DSP2 = 1 ;
DSP3 = 0 ;
LED_DSP = num_led [n3] ;
Delay(1) ;
DSP2 = 0 ; DSP2 activer active
DSP1 = 1 ;
DSP3 = 0 ;
LED_DSP = num_led [n2] ;
Delay(1) ;
DSP2 = 0 ; DSP2 activer active
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) ; Opérateur de division (321/100 = 3)
num = (int)(num%100) ; Opérateur de modules (321 % 100 = 21)
N2 = (int)(num/10) ; Opérateur de division (21/10 = 2)
N3 = (int)(num%10) ;
pour (i = 0; i DSP1 = 1; / / DSP1 activer active
DSP2 = 0 ;
DSP3 = 0 ;
LED_DSP = num_led [n3] ;
Delay(1) ;
DSP2 = 1 ; DSP2 activer active
DSP1 = 0 ;
DSP3 = 0 ;
LED_DSP = num_led [n2] ;
Delay(1) ;
DSP3 = 1 ; DSP2 activer active
DSP1 = 0 ;
DSP2 = 0 ;
LED_DSP = num_led [n1] ;
Delay(1) ;
}
} */