??? 02/01/06 17:53 Read: times |
#108909 - 8255 interfacing with SILABS C8051F226 |
i have been trying to connect the 8255 to interface a 3X4 keypad. i have connected the rows to port B of the 8255 and columns to Port C of the 8255. i am able to write to the 8255 Ports B and C but when i read from the ports B and C i get all zeroes on the I/O port of the 8255.This is my first problem(i am pressing the keys on the keypad to make the ports high while reading from ports B and C). The second problem that i face is that when i output the port data from Port1 of the 226 controller in open drain mode the command doesnt latch into the 8255 even if i give a 1 ms delay between the WR_B=0 WR_B=1 whereas it works fine when i use push pull mode(though when i single step it works fine in open drain mode).so i keep switchin b/w push pull and open drain. Push pull mode to enter data into the 8255 and open drain to receive data. Now when the 226 port is not connected to the I/O port of the 8255 and i issue the read command from PORT C of the 8255 all zeroes come on the 8255 data port whatever be the data is present on port C. The third problem is when i try and read this data on the controller i only get 0XFF when i am in open drain mode. i am pasting a copy of the code.
#include<intrins.h> #include <C8051F200.H> unsigned char key; sbit RD_B=P2^6; // 8255 Pin sbit declarations sbit WR_B=P2^7; sbit A0=P2^4; sbit A1=P2^5; // end of 8255 sbit declarations void delay(unsigned char); void main() { WDTCN = 0xde; // disable watchdog timer WDTCN = 0xad; OSCXCN = 0x67; // start external oscillator with 11.0592MHz clock freq. for (i=0; i < 255; i++) ; // XTLVLD blanking interval (>1ms) while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle OSCICN = 0x08; RD_B=1; WR_B=1; while(1) { PRT1CF=0xff; // setting port 1 push pull mode A1=1; A0=1; // selecting command reg P1=0x89; // setting port b as o/p WR_B=0; // and port c upper and lower delay(1); // as input WR_B=1; A1=0; A0=1; // selecting port B to write data into it P1=0x69;// writing 1s to the rows of keypad WR_B=0; delay(1); WR_B=1; /** ROWS WRITTEN **/ A1=1; A0=0; // selecting port c to read PRT1CF=0x00; // setting port 1 in open drain mode P1=0xff; RD_B=0; delay(1); _nop_(); RD_B=1; //here i get 0x00 on the 8255 I/o port and on P1 read i get 0xff // i checked by disconnecting P1 from the 8255 and observed the status of 8255 data port and it showed me all zeroes but my controller doesnt read these zeroes// key=P1; /******* KEY DETECTION ******/ A1=0; A0=1; P1=0x00; // clearing Port B coz i wanted to clear the latched values WR_B=0; delay(1); WR_B=1; A1=1; A0=1; // selecting command register P1=0x82;// selecting port B as input WR_B=0; // and c as output delay(1); WR_B=1; // written into command register A1=1; A0=0; P1=0xff; // writing into columns WR_B=0; delay(1); WR_B=1; A1=0; A0=1; // selecting port B to read P1=0xff; RD_B=0; delay(1); RD_B=1; key=P1; // same problem i faced as i faced before A1=1; A0=0; P1=0x00; // making port C 0 WR_B=0; delay(1); WR_B=1; } void delay(unsigned char x) { int j; while(x-->0) for(j=0;j<500;j++); } Please note i am fairly new to embedded programming. |