Stap 4: Programmeren in C languagemy lo
#include
#include
#include "24LC256.h"
#include
/*----------------------------------------------------
haven en beetje toewijzing voor LCD ***
----------------------------------------------------*/
#define TH0RELOAD_VALUE 0X3c
#define TL0RELOAD_VALUE 0Xb0
#define wheel_diameter 5
#define TRUE 1
#define LED_DSP P2 / / LED-Display (7 segmenten LED)
typedef unsigned char bit_8;
bit_8 g_byCountOf50ms;
unsigned char num_led [16] code =
{0x3F, 0x06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0x07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0x39, 0x5E, 0x79, //A,b,C,d,E
0x71};
unsigned char sensor_variable, snelheid, switch_inc_variable;
unsigned char waiting_time_chargevariable, charge_pulse;
unsigned char EData;
float distance_temp;
unsigned int afstand = 0, distance_temp2 = 0, distance_temp1;
unsigned int waiting_time_temp, waiting_time, chargevariable, charge_variable = 8;
beetje 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;
beetje run_bit;
code bit_8 * [val] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; cijfer matrix
code unsigned char * route1 [] = {"MP nagar", "MP nagar", "MP nagar", "MP nagar", "MP nagar"};
code unsigned char * route2 [] = {"5-No Stop", "Arera kolonie", "T T Nagar", "Ayodhya", "Piplani"};
code unsigned char * aanrekenen [] = {"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; Selecteer Registreer is poort 3.5
SBIT rw = P0 ^ 1; lezen/schrijven is poort 3.4
SBIT nl P0 = ^ 2; inschakelen is poort 3.3
SBIT d7 = P1 ^ 7; drukke vlag is poort 1.7
SBIT DSP1 P0 = ^ 3; DSP1 inschakelen (actieve laag niveau)
SBIT DSP2 P0 = ^ 4; DSP2 inschakelen (actieve laag niveau)
SBIT DSP3 P0 = ^ 5; DSP3 inschakelen (actieve laag niveau)
SBIT Dot_Point = P2 ^ 7;
SBIT route_selection P0 = ^ 7;
SBIT uitvoeren P0 = ^ 6;
SBIT prepaid P0 = ^ 5;
nietig command(bit_8);
nietig data_in(bit_8*);
nietig initlcd(void);
VOID display_numeric (bit_8);
nietig display_int(unsigned int);
VOID vertraging (unsigned int);
VOID display_led (int num, int dly);
VOID external0 () interrupt 0
{
sensor_variable ++;
charge_pulse ++;
waiting_time_temp = 0;
EX0 = 0;
}
VOID timer1 ()-interrupt 3
{
}
VOID timer0 () interrupt 1
{
TH0 = TH0RELOAD_VALUE;
TL0 = TL0RELOAD_VALUE;
g_byCountOf50ms ++;
if(charge_pulse==10)
{
charge_variable = charge_variable + 2;
charge_pulse = 0;
}
Als (g_byCountOf50ms > = 20)
{
het betekent 1 seconde (50 ms X 20) is voorbij
g_byCountOf50ms = 0;
berekening van de temp afstand voor 1 secound
distance_temp = distance_temp1 = sensor_variable * wheel_diameter;
berekening van de snelheid in 1 secound
snelheid = distance_temp/0.0166;
distance_temp2 = distance_temp2 + distance_temp1;
berekening van de totale distace van de distance_temp1
afstand = distance_temp1 + afstand;
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;
}
}
}
void main()
{
unsigned char route_selection_variable;
route_selection = 1;
lopen = 1;
Prepaid = 1;
initLCD();
Command(0x80);
data_in ("AutomatedDigital");
Command(0xc0);
data_in ("*** Taxi Meter ***");
Command(0x90);
data_in ("Pres * lijst");
Command(0xd0);
data_in ("Pres # To Run");
TMOD = 0X01;
TCON = 0X11;
IE = 0X83;
while(1)
{
if(route_selection==0)
{
Command (0x80);
data_in (route1[route_selection_variable]);
Command (0xc0);
data_in (route2[route_selection_variable]);
Command (0x90);
data_in (charge[route_selection_variable]);
Command (0xd0);
data_in (distance1[route_selection_variable]);
route_selection_variable ++;
vertraging (100);
if(route_selection_variable==4)
{
route_selection_variable = 0;
}
}
if(run==0)
{
run_bit = 1;
initLCD();
IE = 0X83;
}
if(prepaid==0)
{
initLCD();
Command (0x80);
data_in ('Prepaid modus');
Command (0xc0);
data_in ("Klantnummer =");
DelayMs(50);
EData = ReadBYTE(0x00); oplezen
Command (0xcb);
display_int(EData);
Command (0x90);
data_in ("Secret ID =");
EData = ReadBYTE(0x01); oplezen
Command (0x9b);
display_int(EData);
}
if(run_bit==1)
{
EX0 = 1;
Command (0x80);
data_in ("Trav Dist =");
Command (0x8a);
display_int (afstand);
Command (0xc0);
data_in ("snelheid =");
Command (0xc6);
display_int (snelheid);
Command (0xcb);
data_in ("km/hr");
Command (0x90);
data_in ("wachttijd =");
Command (0x9a);
display_int (waiting_time);
Command (0xd0);
data_in ("wacht crgs =");
Command (0xda);
display_int(chargevariable);
display_led(charge_variable,150);
display_led(waiting_time,150);
}
vertraging (1000);
}
}
/*--------------------------
initialisatie van de LCD ***
--------------------------*/
VOID initlcd()
{
Command(56);
Command(0x01);
Command(0x02);
Command(12);
}
/*----------------------------
controle van de drukke vlag ***
----------------------------*/
VOID busy()
{
D7 = 1;
RS = 0;
RW = 1;
while(D7!=0)
{
nl = 0;
nl = 1;
}
}
/*-------------------------
opdracht verzenden LCD ***
-------------------------*/
VOID command(bit_8 val)
{
Busy();
P1 = val;
RS = 0;
RW = 0;
nl = 1;
nl = 0;
}
/*--------------------------
invoeren van gegevens voor LCD ***
--------------------------*/
VOID data_in(bit_8 *string)
{
bit_8 i;
Busy();
for(i=0;string[i]!='\0';i++)
{
P1 = string [i];
RS = 1;
RW = 0;
nl = 1;
nl = 0;
}
}
VOID display_int(unsigned int i)
{
unsigned char ten_thousands, honderden, duizenden, tientallen, degenen;
ten_thousands = i / 10000;
data_in(Val[ten_thousands]);
ik = ik % 10000;
duizenden = i / 1000;
data_in(Val[thousands]);
ik = ik % 1000;
honderden = i / 100;
data_in(Val[hundreds]);
ik = ik % 100;
tientallen = i / 10;
data_in(Val[TENS]);
degenen ik = % 10;
data_in(Val[Ones]);
}
VOID vertraging (unsigned int k)
{
unsigned int i, j;
voor (ik = 0; ik < = k; i ++)
voor (j = 0; j < = 100; j ++);
}
VOID display_led (int num, int dly) {}
int i, n1, n2, n3;
N1 = (int)(num/100); Operator voor delen (53/10 = 5)
num = (int) (num % 100);
N2 =(int) (num/10);
N2 = (int)(num%10); Modules exploitant (53% 10 = 3)
voor (ik = 0; ik DSP1 = 0; / / DSP1 inschakelen actieve
DSP2 = 1;
DSP3 = 0;
LED_DSP = num_led [n3];
delay(1);
DSP2 = 0; DSP2 inschakelen actieve
DSP1 = 1;
DSP3 = 0;
LED_DSP = num_led [n2];
delay(1);
DSP2 = 0; DSP2 inschakelen actieve
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); Operator voor delen (321/100 = 3)
num = (int)(num%100); Modules exploitant (321% 100 = 21)
N2 = (int)(num/10); Operator voor delen (21/10 = 2)
N3 = (int)(num%10);
voor (ik = 0; ik DSP1 = 1; / / DSP1 inschakelen actieve
DSP2 = 0;
DSP3 = 0;
LED_DSP = num_led [n3];
delay(1);
DSP2 = 1; DSP2 inschakelen actieve
DSP1 = 0;
DSP3 = 0;
LED_DSP = num_led [n2];
delay(1);
DSP3 = 1; DSP2 inschakelen actieve
DSP1 = 0;
DSP2 = 0;
LED_DSP = num_led [n1];
delay(1);
}
} */
#include
#include
#include "24LC256.h"
#include
/*----------------------------------------------------
haven en beetje toewijzing voor LCD ***
----------------------------------------------------*/
#define TH0RELOAD_VALUE 0X3c
#define TL0RELOAD_VALUE 0Xb0
#define wheel_diameter 5
#define TRUE 1
#define LED_DSP P2 / / LED-Display (7 segmenten LED)
typedef unsigned char bit_8;
bit_8 g_byCountOf50ms;
unsigned char num_led [16] code =
{0x3F, 0x06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0x07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0x39, 0x5E, 0x79, //A,b,C,d,E
0x71};
unsigned char sensor_variable, snelheid, switch_inc_variable;
unsigned char waiting_time_chargevariable, charge_pulse;
unsigned char EData;
float distance_temp;
unsigned int afstand = 0, distance_temp2 = 0, distance_temp1;
unsigned int waiting_time_temp, waiting_time, chargevariable, charge_variable = 8;
beetje 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;
beetje run_bit;
code bit_8 * [val] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; cijfer matrix
code unsigned char * route1 [] = {"MP nagar", "MP nagar", "MP nagar", "MP nagar", "MP nagar"};
code unsigned char * route2 [] = {"5-No Stop", "Arera kolonie", "T T Nagar", "Ayodhya", "Piplani"};
code unsigned char * aanrekenen [] = {"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; Selecteer Registreer is poort 3.5
SBIT rw = P0 ^ 1; lezen/schrijven is poort 3.4
SBIT nl P0 = ^ 2; inschakelen is poort 3.3
SBIT d7 = P1 ^ 7; drukke vlag is poort 1.7
SBIT DSP1 P0 = ^ 3; DSP1 inschakelen (actieve laag niveau)
SBIT DSP2 P0 = ^ 4; DSP2 inschakelen (actieve laag niveau)
SBIT DSP3 P0 = ^ 5; DSP3 inschakelen (actieve laag niveau)
SBIT Dot_Point = P2 ^ 7;
SBIT route_selection P0 = ^ 7;
SBIT uitvoeren P0 = ^ 6;
SBIT prepaid P0 = ^ 5;
nietig command(bit_8);
nietig data_in(bit_8*);
nietig initlcd(void);
VOID display_numeric (bit_8);
nietig display_int(unsigned int);
VOID vertraging (unsigned int);
VOID display_led (int num, int dly);
VOID external0 () interrupt 0
{
sensor_variable ++;
charge_pulse ++;
waiting_time_temp = 0;
EX0 = 0;
}
VOID timer1 ()-interrupt 3
{
}
VOID timer0 () interrupt 1
{
TH0 = TH0RELOAD_VALUE;
TL0 = TL0RELOAD_VALUE;
g_byCountOf50ms ++;
if(charge_pulse==10)
{
charge_variable = charge_variable + 2;
charge_pulse = 0;
}
Als (g_byCountOf50ms > = 20)
{
het betekent 1 seconde (50 ms X 20) is voorbij
g_byCountOf50ms = 0;
berekening van de temp afstand voor 1 secound
distance_temp = distance_temp1 = sensor_variable * wheel_diameter;
berekening van de snelheid in 1 secound
snelheid = distance_temp/0.0166;
distance_temp2 = distance_temp2 + distance_temp1;
berekening van de totale distace van de distance_temp1
afstand = distance_temp1 + afstand;
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;
}
}
}
void main()
{
unsigned char route_selection_variable;
route_selection = 1;
lopen = 1;
Prepaid = 1;
initLCD();
Command(0x80);
data_in ("AutomatedDigital");
Command(0xc0);
data_in ("*** Taxi Meter ***");
Command(0x90);
data_in ("Pres * lijst");
Command(0xd0);
data_in ("Pres # To Run");
TMOD = 0X01;
TCON = 0X11;
IE = 0X83;
while(1)
{
if(route_selection==0)
{
Command (0x80);
data_in (route1[route_selection_variable]);
Command (0xc0);
data_in (route2[route_selection_variable]);
Command (0x90);
data_in (charge[route_selection_variable]);
Command (0xd0);
data_in (distance1[route_selection_variable]);
route_selection_variable ++;
vertraging (100);
if(route_selection_variable==4)
{
route_selection_variable = 0;
}
}
if(run==0)
{
run_bit = 1;
initLCD();
IE = 0X83;
}
if(prepaid==0)
{
initLCD();
Command (0x80);
data_in ('Prepaid modus');
Command (0xc0);
data_in ("Klantnummer =");
DelayMs(50);
EData = ReadBYTE(0x00); oplezen
Command (0xcb);
display_int(EData);
Command (0x90);
data_in ("Secret ID =");
EData = ReadBYTE(0x01); oplezen
Command (0x9b);
display_int(EData);
}
if(run_bit==1)
{
EX0 = 1;
Command (0x80);
data_in ("Trav Dist =");
Command (0x8a);
display_int (afstand);
Command (0xc0);
data_in ("snelheid =");
Command (0xc6);
display_int (snelheid);
Command (0xcb);
data_in ("km/hr");
Command (0x90);
data_in ("wachttijd =");
Command (0x9a);
display_int (waiting_time);
Command (0xd0);
data_in ("wacht crgs =");
Command (0xda);
display_int(chargevariable);
display_led(charge_variable,150);
display_led(waiting_time,150);
}
vertraging (1000);
}
}
/*--------------------------
initialisatie van de LCD ***
--------------------------*/
VOID initlcd()
{
Command(56);
Command(0x01);
Command(0x02);
Command(12);
}
/*----------------------------
controle van de drukke vlag ***
----------------------------*/
VOID busy()
{
D7 = 1;
RS = 0;
RW = 1;
while(D7!=0)
{
nl = 0;
nl = 1;
}
}
/*-------------------------
opdracht verzenden LCD ***
-------------------------*/
VOID command(bit_8 val)
{
Busy();
P1 = val;
RS = 0;
RW = 0;
nl = 1;
nl = 0;
}
/*--------------------------
invoeren van gegevens voor LCD ***
--------------------------*/
VOID data_in(bit_8 *string)
{
bit_8 i;
Busy();
for(i=0;string[i]!='\0';i++)
{
P1 = string [i];
RS = 1;
RW = 0;
nl = 1;
nl = 0;
}
}
VOID display_int(unsigned int i)
{
unsigned char ten_thousands, honderden, duizenden, tientallen, degenen;
ten_thousands = i / 10000;
data_in(Val[ten_thousands]);
ik = ik % 10000;
duizenden = i / 1000;
data_in(Val[thousands]);
ik = ik % 1000;
honderden = i / 100;
data_in(Val[hundreds]);
ik = ik % 100;
tientallen = i / 10;
data_in(Val[TENS]);
degenen ik = % 10;
data_in(Val[Ones]);
}
VOID vertraging (unsigned int k)
{
unsigned int i, j;
voor (ik = 0; ik < = k; i ++)
voor (j = 0; j < = 100; j ++);
}
VOID display_led (int num, int dly) {}
int i, n1, n2, n3;
N1 = (int)(num/100); Operator voor delen (53/10 = 5)
num = (int) (num % 100);
N2 =(int) (num/10);
N2 = (int)(num%10); Modules exploitant (53% 10 = 3)
voor (ik = 0; ik DSP1 = 0; / / DSP1 inschakelen actieve
DSP2 = 1;
DSP3 = 0;
LED_DSP = num_led [n3];
delay(1);
DSP2 = 0; DSP2 inschakelen actieve
DSP1 = 1;
DSP3 = 0;
LED_DSP = num_led [n2];
delay(1);
DSP2 = 0; DSP2 inschakelen actieve
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); Operator voor delen (321/100 = 3)
num = (int)(num%100); Modules exploitant (321% 100 = 21)
N2 = (int)(num/10); Operator voor delen (21/10 = 2)
N3 = (int)(num%10);
voor (ik = 0; ik DSP1 = 1; / / DSP1 inschakelen actieve
DSP2 = 0;
DSP3 = 0;
LED_DSP = num_led [n3];
delay(1);
DSP2 = 1; DSP2 inschakelen actieve
DSP1 = 0;
DSP3 = 0;
LED_DSP = num_led [n2];
delay(1);
DSP3 = 1; DSP2 inschakelen actieve
DSP1 = 0;
DSP2 = 0;
LED_DSP = num_led [n1];
delay(1);
}
} */