** 7 segment LED display in 'c' **
#include <REGX51.H>
//Port 3's Pin 0->7 define segments a,b,c,d,e,f,g & decimal point
void delay(void);
static code array[16]={0xfc, 0x60, 0xda, 0xf2, 0x66, 0xb6, 0xbe,\
0xe0, 0xfe, 0xf6, 0xee, 0x3e, 0x9c, 0x7a, 0x9e, 0x8e};
void main(){
unsigned char i=0;
while(1){
for(i=0;i<16;i++){
P3 = array[i];
delay();//1 sec delay
}//end of while function
}//end of main function
void delay(void){//Provides fixed delay of around 2 second
int i,j;
for(i=0;i<150;i++)
for(j=0;j<1237;j++)
;
}//end of delay function
==================================================================================================================================================================
** Hex Keypad Interfacing **
#include <REGX51.H>
//Port 1 is used for hex keypad interfacing of 4x4 size
//first 4 pins of it sends scanning signals one by one
//which are fed back to last 4 pins
//if we get 0 on any of the last 4 pins of port 1 during scan
//then we can say perticuliar switch from 0 -> F is turned on
//NOTE : THIS INTERFACING IS DIFFERENT FROM Vcc DRIVEN HEX KEYPADS
//OR Ground DRIVEN HEX KEYPADS
void main(){
unsigned char out[4]={0xFE, 0xFD, 0xFB, 0xF7};
unsigned int i=0,j=0;
unsigned char row=0, column=0,output=100;
while(1){
for(i=0;i<4;i++){
row = i;
//sending data for all rows in hex keypad &
//resetting column status to 1111
P1=out[i];
//Now scanning the received data
if(P1_4==0)
column = 0;
else if(P1_5 == 0)
column = 1;
else if(P1_6 == 0)
column = 2;
else if(P1_7 == 0)
column = 3;
else
column = 10;
//now setting the output variable
if(row<4 && column<4)
output = (row*4)+column;
else
output = 17;
//...space for driving some output according
//to output variable...
P3 = output;//we are just watching the status
//of the output variable on port P3
//.............................................
}//end of for loop
}//end of while loop
}//end of main
No comments:
Post a Comment