Tuesday, July 5, 2016

Arduino code is used to control the PPI 8255



      The code below is written in arduino IDE. The basic purpose of the program is used to control the Programmable Peripheral Interface 8255.

     Arduino nano is used to control the Control Register of PPI 8255 to select the 8255 PORT's.  I choose A0..A5 analog pin and D8..D9 digital pin of arduino nano to make it as data bus connected to D0..D7  data pin of PPI 8255 and then the D2 to D6 of arduino nano pins are used to control the Control pin of PPI 8255.

The output of the code  below, is just simply changing the status of PPI 8255  PORT's  contentiously from high to low or vice versa.  

Materials:

arduino nano
PPI8255
Breadboard
jumper wires
mini usb
multitester
PC with installed arduino IDE
//varable for PPI 8255
byte PPIPortData ;
const byte PPIPortA = 0;
const byte PPIPortB = 1;
const byte PPIPortC = 2;
const byte PPIctrl = 3;
const int PinA0 = 2;
const int PinA1 = 3;
const int PinRead = 4;
const int PinWrite = 5;
const int PinReset = 6;
byte GroupA = B00000111;
byte GroupB = B01111000;
byte PPIMode0 ;
byte PPIMode1 ;
byte PPIMode2 ;
boolean PPImodeEnable;
byte PortX;
//function to read and write the port of PPI 8255
int ReadPPIPort(int ppiPort)
{
//function to read from 8255 port a,b,c
int result;
return result;
}
//function to select the port of PPI 8255
void SelectPort(byte ppiPort)
{
//function to select port oo 8255 port a,b,c
String StrPort;
Serial.print("Port\t");
switch (ppiPort){
case 0: //port a
StrPort="A";
digitalWrite(PinA0,LOW);
digitalWrite(PinA1,LOW);

break;
case 1: //port b
StrPort="B";
digitalWrite(PinA0,HIGH);
digitalWrite(PinA1,LOW);
break;
case 2: //port c
StrPort="C";
digitalWrite(PinA0,LOW);
digitalWrite(PinA1,HIGH);
break;
case 3: //control register
StrPort ="Reg";
digitalWrite(PinA0,HIGH);
digitalWrite(PinA1,HIGH);
break;
}
Serial.print(StrPort + " is selected \n");
}
//write to PPIPOrt
void PPIWrite(byte Portx,byte DataPort)
{
byte PortB0_1;
//select the PPI8255 port
SelectPort(Portx);
//pulldown the write pin of PPI8255
digitalWrite(PinWrite,LOW);
//preset the D0..D5 of PPI8255 data bus
DDRC = DDRC | B00111111; //preset the direction of atmega328 port c into output direction
PORTC = DataPort; //
//preset the D6..D7 of PPI8255 data bus
PortB0_1 = DataPort >> 6;
DDRB = DDRB | B00000011;
PORTB = PortB0_1;
//pullup the write pin of PPI8255
digitalWrite(PinWrite,HIGH);
Serial.print("Writing in Port ... \n");
}
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// put your setup code here, to run once:
Serial.print("Initialize PPI8255 Control I/O ....");
pinMode(PinReset,OUTPUT);
pinMode(PinRead,OUTPUT);
pinMode(PinWrite,OUTPUT);
pinMode(PinA0,OUTPUT);
pinMode(PinA1,OUTPUT);
DDRC = DDRC | B00111111;
digitalWrite(PinReset,LOW);
digitalWrite(PinReset,HIGH);
digitalWrite(PinReset,LOW);
digitalWrite(PinRead,HIGH);
digitalWrite(PinWrite,HIGH);
Serial.print("Done \n");
//INIT control register
SelectPort(PPIctrl);
PORTC = B00000000;
digitalWrite(PinWrite,LOW);
digitalWrite(PinWrite,HIGH);
SelectPort(0);
//PORTC = B11111111;
digitalWrite(PinWrite,LOW);
digitalWrite(PinWrite,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available() > 0 ){
Serial.print("Reading Serial Port\t");
PortX = Serial.parseInt();
SelectPort(PortX);
//Serial.print(PortX );
Serial.print("\t Done \n");
}
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
//SelectPort(0);
//PORTC = B00000000;
//digitalWrite(PinWrite,LOW);
//digitalWrite(PinWrite,HIGH);
PPIWrite(PortX,B11111111);
delay(1000);
//SelectPort(0);
//PORTC = B11111111;
PPIWrite(PortX,B00000000);
//digitalWrite(PinWrite,LOW);
//digitalWrite(PinWrite,HIGH);
delay(1000);
}