Title: 89c51 port epansion with 8255 keil c Post by: Ronydc on January 03, 2008, 10:38:13 10:38 hi friends,
i wanted to increase the port pins with the help of 8255 for 89c51 mcu(atmel) does any one have the c codes that can work with keil uvision (or c51 compiler). i simply require a sample program with which if i push a switch on any port pin of 89c51 and i can lit an LED connected on a single 8255 port pin. your help can make a great fevour for me. Title: Re: 89c51 port epansion with 8255 keil c Post by: leptro on January 03, 2008, 03:18:22 15:18 hello,
i'am not a keil user nor a 8051 user, here's a link to the 8255 datasheet. http://www.datasheetarchive.com/pdf/496740.pdf i've read it quickly and seems to be ease to interface. good luck. Title: Re: 89c51 port epansion with 8255 keil c Post by: bugmike25 on January 03, 2008, 06:10:32 18:10 It is quite simple all u need to do is declare the ports of the 8255:
Usually this is used: //First 8255 IC #define porta1 XBYTE [0x8000] #define portb1 XBYTE [0x8001] #define portc1 XBYTE [0x8002] #define cword1 XBYTE [0x8003] // Second 8255 IC #define porta2 XBYTE [0x9000] #define portb2 XBYTE [0x9001] #define portc2 XBYTE [0x9002] #define cword2 XBYTE [0x9003] //Then set the port functions - input, output etc. See datasheet for more info. example: cword1 = 0x80; //Add short delay here porta1 = 0xff; etc............... Title: Re: 89c51 port epansion with 8255 keil c Post by: Ronydc on January 03, 2008, 06:36:30 18:36 thanks leptro and bugmike25.
bug, its a nice thing that you have suggested but this do not work with keil. --> xbyte[0x .... ] // even if we use the absacc.h header file. i found out that _at_ key word works well with keil. like --> char xdata PA _at_ 0x8000; char xdata CR _at_ 0x8003; and we can take xdata char as--> char xdata j; so that we can put, void initPPI() { / CR = 0x80; /* set all port for output */ } main() { while(1) { j = PA; /* read total port A into j*/ } } now my problem is.. how to read (or write onto) ON A SINGLE PIN of the port..? can some one try for the code to push a switch on port pin P0.1 and lit an LED on 8255 port pin PA .2 ...? PLEASE HELP. THANKS Title: Re: 89c51 port epansion with 8255 keil c Post by: bugmike25 on January 03, 2008, 06:42:59 18:42 It works for sure with Keil. What version are u using? I use uVision3. You must include that header file:
#include <absacc.h> Title: Re: 89c51 port epansion with 8255 keil c Post by: Ronydc on January 03, 2008, 06:45:51 18:45 i am using uvision2... any way. but still my problems stands.
what to do for the access for a single port pin as i have write in the last paragraph. Title: Re: 89c51 port epansion with 8255 keil c Post by: bugmike25 on January 03, 2008, 07:02:37 19:02 I just found a more recent source code which isnt mine which uses the commands u used. They only work with the recent versions of Keil (after ARM bought Keil) because i have an older version and that command does not work.
Now if u need to output on port A, pin 2 of the 8255 u must set ur control word to 1000XXXX = 0x80 This means that the 8255 is set to mode 0: basin i/o operation and port A is set as output. Now when u are dealing with a port is must be treated at a byte. Therefore if u need to use another pin on Port A for a completely different application you can do this: Create a variable of unsigned char temp=0, Then use a variable of type bit to set the state of ur LED; name it LED1, Then set temp = temp|LED1; and then shift left using the << command to place the bit in the correct position. This can be done for many different LEDx states. Then using portA = temp; However, u cannot just set a single bit on the 8255, you must treat is as a byte. Title: Re: 89c51 port epansion with 8255 keil c Post by: Ronydc on January 03, 2008, 07:27:38 19:27 THX BUG ,
in short i got it, that as you said, the same can be done in following way. if i want to lit a single led on any port pin.. i have to put there a port value. like PA = 0X10; or PA = 20; ( this is ment for some pins on and some off..) and like tht the port value for the required port pin. yes.. this enlitans my mind... dear friend..!! THANKS. thanks a lot for your quick helps. Title: Re: 89c51 port epansion with 8255 keil c Post by: sjn on January 12, 2008, 05:01:26 17:01 #define LCD_DATA XBYTE [0xE000] // Port A
#define KEY_OUT XBYTE [0xE001] // Port B #define KEY_IN XBYTE [0xE002] // Port C #define CONTROL_PORT XBYTE [0xE003] // Control Port #define CONTROL_WORD 0x89 // Port A => O/P , B => O/P , C => I/P ..... void main(void) { unsigned char j; delay(1000); CONTROL_PORT = CONTROL_WORD; ... LCD_DATA = 0x00; } Title: Re: 89c51 port epansion with 8255 keil c Post by: Ronydc on January 29, 2008, 07:57:22 19:57 we had a good discussion abt 8255 ports and pins . thanks friends.
but i have found the shortest way for solving my fundamental problem. and that is--> to use the switches in matrix form. i can use as many switches i like if thay are in matrix. and the output too i suppose. thanks any way. |