In: Electrical Engineering
To develop a program for the PIC 16F84A using either MPLAB X IDE simulator software. T
he PIC 16F84A has 8 LEDs connected to Port B. The program is to convert your student number (10 ASCII characters), taken in reverse order, one character at a time, to Gray code.
Each converted character is to be displayed on 4 of the LEDs connected to Port B (B0 to B3) of the microcontroller.
Further, each converted character will be displayed for 3 seconds, with the LEDs turned OFF for 1 second between each character. Once all characters have been displayed the program will continue to run with all of the Port B LEDs flashing in a pattern of Odd Numbered LEDs On and Even Numbered LEDS Off for 1 second, and then Odd Numbered LEDs Off and Even Numbered LEDS On for 1 second. This pattern will repeat indefinitely.
Input code:-
int led = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
int led5 = 9;
int led6 = 6;
int led7 = 5;
int led8 = 3;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
{digitalWrite(led, HIGH);
delay (15);
digitalWrite(led, LOW);
delay(15);
digitalWrite(led, HIGH);
delay(15);
digitalWrite(led, LOW);
delay(15);}
{digitalWrite(led2, HIGH);
delay (15);
digitalWrite(led2, LOW);
delay(15);
digitalWrite(led2, HIGH);
delay(15);
digitalWrite(led2, LOW);
delay(15);}
{digitalWrite(led3, HIGH);
delay (15);
digitalWrite(led3, LOW);
delay(15);
digitalWrite(led3, HIGH);
delay(15);
digitalWrite(led3, LOW);
delay(15);}
{digitalWrite(led4, HIGH);
delay (15);
digitalWrite(led4, LOW);
delay(15);
digitalWrite(led4, HIGH);
delay(15);
digitalWrite(led4, LOW);
delay(15);}
{digitalWrite(led5, HIGH);
delay (15);
digitalWrite(led5, LOW);
delay(15);
digitalWrite(led5, HIGH);
delay(15);
digitalWrite(led5, LOW);
delay(15);}
{digitalWrite(led6, HIGH);
delay (15);
digitalWrite(led6, LOW);
delay(15);
digitalWrite(led6, HIGH);
delay(15);
digitalWrite(led6, LOW);
delay(15);}
{digitalWrite(led7, HIGH);
delay (15);
digitalWrite(led7, LOW);
delay(15);
digitalWrite(led7, HIGH);
delay(15);
digitalWrite(led7, LOW);
delay(15);}
{digitalWrite(led8, HIGH);
delay (15);
digitalWrite(led8, LOW);
delay(15);
digitalWrite(led8, HIGH);
delay(15);
digitalWrite(led8, LOW);
delay(15);
{digitalWrite(led8, HIGH);
delay (15);
digitalWrite(led8, LOW);
delay(15);
digitalWrite(led8, HIGH);
delay(15);
digitalWrite(led8, LOW);
delay(15);}
{digitalWrite(led7, HIGH);
delay (15);
digitalWrite(led7, LOW);
delay(15);
digitalWrite(led7, HIGH);
delay(15);
digitalWrite(led7, LOW);
delay(15);}
{digitalWrite(led6, HIGH);
delay (15);
digitalWrite(led6, LOW);
delay(15);
digitalWrite(led6, HIGH);
delay(15);
digitalWrite(led6, LOW);
delay(15);}
{digitalWrite(led5, HIGH);
delay (15);
digitalWrite(led5, LOW);
delay(15);
digitalWrite(led5, HIGH);
delay(15);
digitalWrite(led5, LOW);
delay(15);}
{digitalWrite(led4, HIGH);
delay (15);
digitalWrite(led4, LOW);
delay(15);
digitalWrite(led4, HIGH);
delay(15);
digitalWrite(led4, LOW);
delay(15);}
{digitalWrite(led3, HIGH);
delay (15);
digitalWrite(led3, LOW);
delay(15);
digitalWrite(led3, HIGH);
delay(15);
digitalWrite(led3, LOW);
delay(15);}
{digitalWrite(led2, HIGH);
delay (15);
digitalWrite(led2, LOW);
delay(15);
digitalWrite(led2, HIGH);
delay(15);
digitalWrite(led2, LOW);
delay(15);}
{digitalWrite(led, HIGH);
delay (15);}
digitalWrite(led, LOW);
delay(15);
digitalWrite(led, HIGH);
delay(15);
digitalWrite(led, LOW);
delay(15);}
}