Hello!
Can you help me please.
I am a student and i have some problems with one task.
I had to write a program for an embedded system which will have 8 buttons and will show on 7-segment display the number of the button pressed last.
I wrote the program but the teacher said that i must use external interrupts and that i can't use polling.I can't quite figure out what should i do next and how to fix my code so that it will fit the teachers demands.
Here is the code that i wrote and the scheme in proteus.
Thanks in advance,hope you can help me.
#include <reg51.h>
sbit in1=P1^0; // input pins
sbit in2=P1^1;
sbit in3=P1^2;
sbit in4=P1^3;
sbit in5=P1^4;
sbit in6=P1^5;
sbit in7=P1^6;
sbit in8=P1^7;
sbit ou1=P2^0; // output pins
sbit ou2=P2^1;
sbit ou3=P2^2;
sbit ou4=P2^3;
sbit ou5=P2^4;
sbit ou6=P2^5;
sbit ou7=P2^6;
void main()
{
in1 = in2 = in3 = in4 = in5 = in6 = in7 = in8 = 1; // Initialize the input pin
ou1 = ou2 = ou3 = ou4 = ou5 = ou6 = ou7 = 1;
while(1)
{
if (in1==0)
{
ou2 = ou3 = 0;
ou1 = ou4 = ou5 = ou6 = ou7 = 1;
}
if (in2==0)
{
ou1 = ou2 = ou4 = ou5 = ou7 = 0;
ou3 = ou6 = 1;
}
if (in3==0)
{
ou1 = ou2 = ou4 = ou3 = ou7 = 0;
ou5 = ou6 = 1;
}
if (in4==0)
{
ou3 = ou2 = ou6 = ou7 = 0;
ou1 = ou4 = ou5 = 1;
}
if (in5==0)
{
ou1 = ou3 = ou4 = ou6 = ou7 = 0;
ou2 = ou5 = 1;
}
if (in6==0)
{
ou1 = ou5 = ou3 = ou4 = ou6 = ou7 = 0;
ou2 = 1;
}
if (in7==0)
{
ou1 = ou3 = ou2 = 0;
ou4 = ou5 = ou6 = ou7 = 1;
}
if (in8==0)
{
ou1 = ou2 = ou5 = ou3 = ou4 = ou6 = ou7 = 0;
}
}
}
on the link bellow you can see the proteus simulation