#include "Includes.h"

#define R1 PORTAbits.RA0
#define Y1 PORTAbits.RA1
#define G1 PORTAbits.RA2
#define R2 PORTAbits.RA3
#define Y2 PORTAbits.RA4
#define G2 PORTAbits.RA5
#define R3 PORTBbits.RB0
#define Y3 PORTBbits.RB1
#define G3 PORTBbits.RB2
#define R4 PORTBbits.RB3
#define Y4 PORTBbits.RB4
#define G4 PORTBbits.RB5
#define a PORTCbits.RC0
#define b PORTCbits.RC1
#define c PORTCbits.RC2
#define d PORTCbits.RC3
#define e PORTCbits.RC4
#define f PORTCbits.RC5
#define pg PORTBbits.RB6

#define pr PORTBbits.RB7
//void main(void)
//{
void main(void)
{
 unsigned int Count,pulserate,count1,i;
const char s1[30]="B.Sc FINAL PROJECT\0";
const char s2[30]="DEN Bas TRAF\0";
const char s3[17]="SHELL ROAD\0";
 const char s4[13]="GORO ROAD\0";
 const char s5[14]="SABTANYA ROAD\0";
 const char s6[13]="TONY ROAD\0";
const char s7[26]="MORE DENSITY\0";
 const char s8[17]=" HAPPY JOURNEY\0";
 const char s9[25]=" pedastrion move\0";
 const char s10[25]=" pedastrion stop\0";
TRISA = 0x00;
TRISB = 0x00;
 //TRISC = 0xff;
TRISCbits.TRISC0=1;
TRISCbits.TRISC1=1;
TRISCbits.TRISC2=1;
 TRISCbits.TRISC3=1;
 TRISCbits.TRISC4=0;
TRISCbits.TRISC3=1;
 TRISCbits.TRISC5=0;
PORTA = 0;
PORTB = 0;
 InitLCD();
ClearLCDScreen(); // Clear LCD screen
 WriteStringToLCD(s1);
 WriteCommandToLCD(0xC0);
 WriteStringToLCD(s2);
 //__delay_ms(20000);
 InitLCD();
//e=0;
//f=0;
// WriteStringToLCD(s2); // Write Message on LCD
 while(1)
 {
 if(a==0)
{
 PORTA =0x0C;
 PORTB =0x89; 
 f=1; 
 ClearLCDScreen(); // Clear LCD screen
 WriteStringToLCD(s3);
 WriteCommandToLCD(0xC0);
WriteStringToLCD(s7);
 __delay_ms(10000);
 ClearLCDScreen();
 WriteStringToLCD(s10);
 //__delay_ms(5000);
 PORTA =0x09;
 PORTB =0x49; 
 f=1;
 ClearLCDScreen();
 WriteStringToLCD(s9);
 __delay_ms(5000);
}
else if(b==0)
{
 PORTA =0x21;
 PORTB =0x89; 
 f=1; 
 ClearLCDScreen(); // Clear LCD screen
 WriteStringToLCD(s4);
 WriteCommandToLCD(0xC0);
 WriteStringToLCD(s7);
 __delay_ms(10000);
 ClearLCDScreen();
 WriteStringToLCD(s10);
//__delay_ms(5000);
 PORTA =0x09;
 PORTB =0x49; 
 f=1;
 ClearLCDScreen();
 WriteStringToLCD(s9);
 __delay_ms(5000);
}
else if(c==0)
{
 PORTA =0x09;
 PORTB =0x8C; 
 f=1; 
 ClearLCDScreen(); // Clear LCD screen
 WriteStringToLCD(s5);
 WriteCommandToLCD(0xC0);
 WriteStringToLCD(s7);
 __delay_ms(10000);
 ClearLCDScreen();
 WriteStringToLCD(s10);
 //__delay_ms(5000);
 PORTA =0x09;
 PORTB =0x49; 
 f=1;
PORTC=0x00100000b;
 ClearLCDScreen();
 WriteStringToLCD(s9);
 __delay_ms(5000);
 }
else if(d==0)
{
 PORTA =0x09;
 PORTB =0xA1; 
 ClearLCDScreen(); // Clear LCD screen
 WriteStringToLCD(s6);
 WriteCommandToLCD(0xC0);
 WriteStringToLCD(s7);
 __delay_ms(10000);
 ClearLCDScreen();
 WriteStringToLCD(s10);
 //__delay_ms(5000);
 PORTA =0x09;
 PORTB =0x49; 
 f=1;
 ClearLCDScreen();
 WriteStringToLCD(s9);
 __delay_ms(5000);
 }
else
{
 ClearLCDScreen(); // Clear LCD screen
 WriteStringToLCD(s8);
 WriteCommandToLCD(0xC0);
 WriteStringToLCD(s10);
 PORTA = 0x00;
 PORTB = 0x00;
 PORTA =0x0C;
 PORTB =0x89;
 f=1;
 __delay_ms(10000);
 PORTA =0x12;
 PORTB =0x89;
 e=1;
 f=1;
 __delay_ms(5000);
 PORTA = 0x00;
 PORTB = 0x00;
 e=0;
 PORTA =0x21;
 PORTB =0x89;
 f=1;
 __delay_ms(10000);
 PORTA =0x11;
 PORTB =0x89;
 e=1;
 f=1;
 __delay_ms(5000);
PORTA = 0x00;
PORTB = 0x00;
 // f=0;
//pedastrian move
 PORTA =0x09;
 //f=1;
 PORTB =0x49; 
 f=1;
 e=0;
 PORTC=0x20;
 ClearLCDScreen();
 WriteStringToLCD(s9);
 __delay_ms(10000);
 ClearLCDScreen();
 WriteStringToLCD(s10);
 ClearLCDScreen(); // Clear LCD screen
 WriteStringToLCD(s8);
WriteCommandToLCD(0xC0);
 WriteStringToLCD(s10);
 PORTA =0x09;
PORTB =0x8C;
 f=1;
 __delay_ms(10000);
PORTA =0x09;
PORTB =0x92;
 f=0; 
 e=0;
 //f=1;
__delay_ms(5000);
PORTA = 0x00;
PORTB = 0x00;
PORTA =0x09;
PORTB =0xA1;
__delay_ms(10000);
PORTA =0x0A;
PORTB =0x91;
 e=0;
__delay_ms(5000);
PORTA = 0;
PORTB = 0;
}
 }
} 

C Language online compiler

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!

Read inputs from stdin

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;
    
}

About C

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.

Key features:

  • Structured Programming
  • Popular system programming language
  • UNIX, MySQL and Oracle are completely written in C.
  • Supports variety of platforms
  • Efficient and also handle low-level activities.
  • As fast as assembly language and hence used as system development language.

Syntax help

Loops

1. If-Else:

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.

2. Switch:

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;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  // code  
} 

4. While:

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 
}  

5. Do-While:

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); 

Arrays

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.

Syntax

One dimentional Array:

data-type array-name[size];

Two dimensional array:

data-type array-name[size][size];

Functions

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

  1. Library Functions:

Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,

  1. User defined functions:

User defined functions are the ones which are written by the programmer based on the requirement.

How to declare a Function

return_type function_name(parameters);

How to call a Function

function_name (parameters)

How to define a Function

return_type function_name(parameters) {  
  //code
}