help on 8051 project

Thread Starter

seahcy

Joined Dec 11, 2007
5
Hi
I am new at C programming. Can you please give me the
code for writing a program using a 4x3 keypad with a 74c922 encoder
chip in C? I know that when your DA pin is set high, it tells the
program that data is available, but how do you tell the code to go
fetch the data? When the DA pin goes high, it must trigger an external interrupt(INT0) and then it must detect whick key was pressed according the encoder chip.

Any help would be greatly appreciated!

Regards and Thanks:D
 

Papabravo

Joined Feb 24, 2006
21,158
The DA(Data Available) pin is connected to an 8051 input. When it goes to the proper state. You can read the data from Data Out A through Data Out E. You need to either wire the Output Enable bar to ground or better yet connect it to an 8051 output and take it low before reading the Data Out pins, then take it high again. This way you can share several devices on the same pins.

Remember Port 0 has open drain outputs requiring an external pullup resistor if they are used as outputs. The remaining ports 1, 2 and 3 are quasi bi directional. They have waek pullups and can sink way more current than they can source.
 

Thread Starter

seahcy

Joined Dec 11, 2007
5
Thanks a lot.. But how do i program it? As i am quite new to c programming.. i am using P0.2 for DA and P2.4 to P2.7 for Data out A to Data out D. hw does it capture which key has been pressed?:confused:
 

Papabravo

Joined Feb 24, 2006
21,158
You treat the port bits and other SFRs(special function registers) as if they were memory locations. Now each C compiler handles things a bit differently so you will have to find examples in the compiler's documentation.

Rich (BB code):
#define  DA   P1.4    // DA is bit 4 of port 1
#define  OE   P1.0    // OE is bit 0 of port 1
#define  KY   P2      // KY is the keyboard input on bits P2.4 thru P2.0
 
unsigned char getkey(void)
{
unsigned char key ;
 
     if (DA == 0) return '\xFF';  // return out of range value if no key
     OE = 0 ;
     key = KY ;
     OE = 1 ;
     return key ;
}
Be sure to find the compiler option that will generate a listing file so you can check that the compiler generated the correct code. There really is no substitute for this step when you are learning your way around a new processor.
 

Thread Starter

seahcy

Joined Dec 11, 2007
5
Thanks for the help.:)

Hmm.. just to ask.. is there any links to learning c programming to program 8051? or learn hw to apply the codes for 8051?
 

Thread Starter

seahcy

Joined Dec 11, 2007
5
Thank for the info.

just to ask..
hw should i go about using timer to do a scan for the 4x3 keyboard every 100ms and what is the code for it?

Any help would be greatly appreciated!

Regards and Thanks:)
 

mrmeval

Joined Jun 30, 2006
833
The 74c922 does all that, read page 8 of the datasheet. http://www.octopart.com will lead you to the datasheet. When the data available pin goes high read the data on the encoded outputs (page 2). There are several examples and several more you can find online.

As to code? You'll have to start studying some language that is compatible with that microcontroller that offers you what you want to do. Or learn several.
 

Thread Starter

seahcy

Joined Dec 11, 2007
5
Thanks, mrmeval :)

Just to ask.. how to write the program for the LED to blink 3 times using c language? do i need to declare the variable in the global function?

Any help would be greatly appreciated!:D
 
Top