#include<stdio.h> #include<string.h> sbit START_POINT=P1^3; sbit TERMINATE_POINT=P1^4; sbit S1=P3^2; sbit S2=P3^3; sbit rc1=P1^1; sbit rc2=P1^2; sbit BUZZPORT=P1^7; sbit RS=P3^7; sbit EN=P3^6; void lcdinit(); void lcdData(unsigned char l); void lcdcmd(unsigned char k); void buzzer(unsigned int time); void DelayMs(unsigned int count); void display(unsigned char s,t,u); void Welcome(unsigned char c[],unsigned char d[]); void ConvertAndDisplay(unsigned int value1,unsigned char c[]); void dcMotor(); void main() { unsigned char i=0,j=0,result=0; unsigned int count; unsigned char c[15]; unsigned char d[]="42006B1BB8"; signed int amount2=900; TMOD=0x20; // To configure the serial port at 9600 baud rate TH1=0xFD; SCON=0X50; TR1=1; S1=1; S2=1; BUZZPORT=0; START_POINT=0; TERMINATE_POINT=0; lcdinit(); Welcome("AUTOMATIC RFID","CAR PARKING"); DelayMs(1000); while(1) { known: while(S1==1 && S2==1); if(S2==0) { while(S2==0); if(count>0) { count--; ConvertAndDisplay(count,"Thanks for Visit"); DelayMs(1000); goto known; } else { count=0; ConvertAndDisplay(count,"Thanks for Visit"); DelayMs(1000); goto known; } } if(S1==0) { while(S1==0); for(i=0;i<12;i++) { c[i]=0xFF; } while(RI==0); for(i=0;i<12;i++) //command to recv data { j=0; while(RI==0) { if(j>=1000) goto timeout; DelayMs(1); j++; } c[i]=SBUF; RI=0; } timeout: i=strncmp(c,d,10); if(result==0 && count<10) { lcdinit(); Welcome("VEHICAL1 Amount ","Detected:100"); DelayMs(1000); amount2-=100; if(amount2>0) { ConvertAndDisplay(amount2,"Balance Amount"); dcMotor(); } else { amount2=0; Welcome("VEHICAL1 Amount ","BALANCE NIL"); buzzer(500); Welcome("Recharge Your","Card Please"); while(rc1==1&&rc2==1); { if(rc1==0) { while(rc1==0); amount2=900; Welcome("Card is recharged","with amount 900"); } if(rc2==0) { while(rc2==0); amount2=500; Welcome("Card is recharged","with amount 500"); } } } if(amount2==400) { Welcome("VEHICAL1 Amount ","BALANCE LOW"); buzzer(200); } DelayMs(1000); count++; lcdcmd(0x01); DelayMs(10); ConvertAndDisplay(count,"Number of Cars"); goto known; } else { Welcome("Parking is Full","Sorry for Inconvenience"); buzzer(500); DelayMs(1000); goto known; } } } } void Welcome(unsigned char c[],unsigned char d[]) { unsigned int i=0; lcdcmd(0x01); DelayMs(10); lcdcmd(0x80); DelayMs(10); i=0; while(c[i]!='\0') { lcdData(c[i]); i++; } lcdcmd(0xc0); DelayMs(10); i=0; while(d[i]!='\0') { lcdData(d[i]); i++; } } void ConvertAndDisplay(unsigned int value1,unsigned char c[]) { unsigned int i,a=0,j; unsigned char d1,d2,d3; for(i=0;i<value1;i++) a=a+1; lcdcmd(0x01); DelayMs(10); lcdcmd(0x80); DelayMs(10); j=0; while(c[j]!='\0') { lcdData(c[j]); j++; } d1=a%10; //digits before desible point a=a/10; d2=a%10; a=a/10; d3=a%10; lcdcmd(0xc0); DelayMs(10); display(d1,d2,d3); } //--------------------------------------- // Lcd initialization subroutine //--------------------------------------- void lcdinit(void) { lcdcmd(0x38); DelayMs(250); lcdcmd(0x0E); DelayMs(250); lcdcmd(0x01); DelayMs(250); lcdcmd(0x06); DelayMs(250); lcdcmd(0x80); DelayMs(250); } //--------------------------------------- // Lcd data display //--------------------------------------- void lcdData(unsigned char l) { P2=l; RS=1; EN=1; DelayMs(1); EN=0; return; } //--------------------------------------- // Lcd command //--------------------------------------- void lcdcmd(unsigned char k) { P2=k; RS=0; EN=1; DelayMs(1); EN=0; return; } //--------------------------------------- // Delay mS function //--------------------------------------- void DelayMs(unsigned int count) { // mSec Delay 11.0592 Mhz unsigned int i; // Keil v7.5a while(count) { i = 115; // 115 exact value while(i>0) i--; count--; } } void dcMotor() { START_POINT=1; TERMINATE_POINT=0; DelayMs(400); START_POINT=0; TERMINATE_POINT=0; DelayMs(2000); START_POINT=0; TERMINATE_POINT=1; DelayMs(400); START_POINT=0; TERMINATE_POINT=0; } void display(unsigned char s,t,u) { s=s+0x30; //convert each digit to equivalent ASCII value t=t+0x30; u=u+0x30; //Move the cursor to position 5 on LCD DelayMs(50); lcdData(u); //Display the digits one by one on LCD DelayMs(50); lcdData(t); DelayMs(50); lcdData(s); DelayMs(50); } void buzzer(unsigned int time) { BUZZPORT=1; DelayMs(time); BUZZPORT=0; }
Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!
OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.
#include <stdio.h>
int main()
{
char name[50];
printf("Enter name:");
scanf("%s", name);
printf("Hello %s \n" , name );
return 0;
}
C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.
When ever you want to perform a set of operations based on a condition if-else
is used.
if(conditional-expression) {
// code
} else {
// code
}
You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to if-else-if ladder.
switch(conditional-expression) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
// code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
// code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.
data-type array-name[size];
data-type array-name[size][size];
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Two types of functions are present in C
Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,
User defined functions are the ones which are written by the programmer based on the requirement.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
//code
}