![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
my problem is whit a 24LC256 and a pic 18f1320, that pic haven´t pins for I2C comunication, but the C18 libraries contain functions to make that comunication, I changed the pins default whit pin RA1 for clock and RA4 for data, I already recompile the function, and I can see in proteus that the pins works well, the problem is that I cant write or read, when I try to read the LCD shows only extrangers characters, and for that reason I don´t think that the write function is well. I´m lookin for some help or and advise because I´m tired to try and fail, I got the pull up resistor on the SDA and SCL pins, 2 Kohm for each, I think that is an common error, but I cant find the reason, Im new whit memories, I post my code for some help. thank you. the keypad 4X4 works whit an ADC in the pin RA1, the option 1 for read, the second one is for write, and the trhird one is for show the adquiered value, the option 1 (tecla 1) takes the value of "contador" (seted to 35), and changed of int to char, and this values is writen in the location 0000 of the memory. then in option 2( tecla 2), read that position of memory and the value is saved to i2c, and then option 3 (tecla 3) is for show value of contador, and then the value of i2c, both values must be equal, but the value of i2c always is extranger, what is my problem??? #include <p18f1320.h> #include <delays.h> #include <adc.h> #include <xlcd.h> #include <sw_i2c.h> #include <stdlib.h> #include <stdio.h> #pragma config OSC=XT, WDT=OFF, MCLRE=ON, LVP=OFF void DelayFor18TCY( void ) { Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); } void DelayPORXLCD (void) { Delay1KTCYx(60); // Delay of 15ms // Cycles = (TimeDelay * Fosc) / 4 // Cycles = (15ms * 16MHz) / 4 // Cycles = 60,000 return; } void DelayXLCD (void) { Delay1KTCYx(20); // Delay of 5ms // Cycles = (TimeDelay * Fosc) / 4 // Cycles = (5ms * 16MHz) / 4 // Cycles = 20,000 return; } void main(void) { int dato,x,otra,cont,contador2; unsigned char buf[9],cosa,contchar,i2c,nuevo; ADCON1=0x7F; TRISA=0x0F; TRISB=0x00; PORTBbits.RB7=0; OpenXLCD( FOUR_BIT & LINES_5X7 ); WriteCmdXLCD( BLINK_ON ); putrsXLCD("ESIME CULHUACAN"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); putrsXLCD("1ER AVANCE"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); cont=35; while(1) { /*Inicializa el convertidor ADC con canal 0 como entrada analógica */ OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS & ADC_CH0 & ADC_INT_OFF, 0x7E ); SetDDRamAddr(0x00); //while(BusyXLCD()); putrsXLCD("PRESIONA UNA TECLA"); do{ x=0; ConvertADC(); while(BusyADC()); dato= ReadADC(); }while(dato<20); while(BusyXLCD()); if(dato>855&&dato<875) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 1"); Delay1KTCYx(10); itoa(cont, contchar); WriteCmdXLCD( 0x01 ); SWStartI2C(); SWPutcI2C(0xA0); // control byte SWAckI2C(); SWPutcI2C(0x00); // address high byte SWAckI2C(); SWPutcI2C(0x00); //address low byte SWAckI2C(); SWPutcI2C(contchar); // data SWAckI2C(); SWStopI2C(); Delay100TCYx(100); } if(dato>645&&dato<655) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 2"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); SWStartI2C(); SWPutcI2C(0xA0); // control byte SWAckI2C(); SWPutcI2C(0x00); // address high byte SWAckI2C(); SWPutcI2C(0x00); //address low byte SWAckI2C(); SWStartI2C(); SWPutcI2C(0xA1); SWAckI2C(); i2c=SWGetcI2C(); // data SWNotAckI2C(); SWStopI2C(); Delay100TCYx(100); WriteCmdXLCD( 0x01 ); } if(dato>495&&dato<515) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 3"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); itoa(cont, nuevo); putsXLCD( nuevo ); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); putsXLCD( i2c ); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } if(dato>335&&dato<345) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 4"); cont++; Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } if(dato>797&&dato<809) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 5"); Delay1KTCYx(10); } if(dato>610&&dato<621) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 6"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } if(dato>480&&dato<491) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 7"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } if(dato>322&&dato<333) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 8"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } if(dato>728&&dato<740) { WriteCmdXLCD( 0x01 ); putrsXLCD("tecla 9"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } if(dato>568&&dato<580) { WriteCmdXLCD( 0x01 ); putrsXLCD("corrertecla"); do{ //WriteCmdXLCD( 0x01 ); Delay1KTCYx(10); WriteCmdXLCD( SHIFT_CUR_LEFT ); x++; }while(x<4); Delay1KTCYx(10); while ( BusyXLCD() ); cosa = ReadDataXLCD(); btoa(cosa, buf); WriteCmdXLCD( 0x01 ); putsXLCD(buf); Delay1KTCYx(10); atoi(cosa); WriteCmdXLCD( 0x01 ); putsXLCD(cosa); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } CloseADC(); while(BusyADC()); } } | |
| |
| | #2 |
|
Reduce your code to just read and write the EEPROM and then post it again. When you repost it place Code: before it and A quick glance at your code makes me wonder if you need to set the two lines to input and low prior to calling StartI2C and after writing an address you should do a restart. Mike. | |
| |
| | #3 |
|
hi and thanks Pommie, I changed the pins for inputs, but the problem remains, I dont understand what you mean whit change to LOW, because a start condition is a change from HI to LOW of the SDA (I think so), its still showing a null character ( empty ) when I want to display, I am thinking that maybe are the delays, but I don´t know where to put them, I repost my code whit pin changed to inputs, can you see something extrange??? thanks a lot for your help. #include <p18f1320.h> #include <delays.h> #include <adc.h> #include <xlcd.h> #include <sw_i2c.h> #include <stdlib.h> #include <stdio.h> #pragma config OSC=INTIO2, WDT=OFF, MCLRE=ON, LVP=OFF void DelayFor18TCY( void ) { Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); } void DelayPORXLCD (void) { Delay1KTCYx(60); // Delay of 15ms // Cycles = (TimeDelay * Fosc) / 4 // Cycles = (15ms * 16MHz) / 4 // Cycles = 60,000 return; } void DelayXLCD (void) { Delay1KTCYx(20); // Delay of 5ms return; } void main(void) { int dato,x,cont,contador2,cosa; unsigned char contchar,i2c,nuevo,buf[9]; ADCON1=0x7F; TRISA=0b11111111; TRISB=0x00; PORTBbits.RB7=0; OpenXLCD( FOUR_BIT & LINES_5X7 ); WriteCmdXLCD( BLINK_ON ); cont=35; while(1) { /*Inicializa el convertidor ADC con canal 0 como entrada analógica */ OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS & ADC_CH0 & ADC_INT_OFF, 0x7E ); SetDDRamAddr(0x00); putrsXLCD("PRESIONA UNA TECLA"); do{ x=0; ConvertADC(); while(BusyADC()); dato= ReadADC(); }while(dato<20); while(BusyXLCD()); if(dato>855&&dato<875) { itoa(cont, contchar); WriteCmdXLCD( 0x01 ); SWStartI2C(); SWPutcI2C(0xA0); // control byte SWAckI2C(); SWPutcI2C(0x00); // address high byte SWAckI2C(); SWPutcI2C(0x00); //address low byte SWAckI2C(); SWWriteI2C(contchar); // data SWAckI2C(); SWStopI2C(); Delay100TCYx(100); } if(dato>645&&dato<655) { SWStartI2C(); SWPutcI2C(0xA0); // control byte SWAckI2C(); SWPutcI2C(0x00); // address high byte SWAckI2C(); SWPutcI2C(0x00); //address low byte SWAckI2C(); SWStartI2C(); SWPutcI2C(0xA1); SWAckI2C(); i2c=SWReadI2C();// data SWNotAckI2C(); SWStopI2C(); Delay100TCYx(100); WriteCmdXLCD( 0x01 ); } if(dato>495&&dato<515) { WriteCmdXLCD( 0x01 ); putrsXLCD("show values"); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); itoa(cont, nuevo); putsXLCD( nuevo ); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); putsXLCD( i2c ); Delay1KTCYx(10); WriteCmdXLCD( 0x01 ); } CloseADC(); while(BusyADC()); } } | |
| |
| | #4 |
|
You forgot to use code tags. Use the Go Advanced button to get that option.
| |
| |
| | #5 |
|
See below. Code: SWPutcI2C(0x00); // address high byte SWAckI2C(); SWPutcI2C(0x00); //address low byte SWAckI2C(); SWStartI2C(); //this should be a restart. SWPutcI2C(0xA1); SWAckI2C(); Mike. | |
| |
|
| Tags |
| body |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| can some body help me with this circuits ??? | delokaver | Electronic Projects Design/Ideas/Reviews | 2 | 7th November 2008 06:18 PM |
| hello every body | engineers feel | Robotics Chat | 5 | 16th June 2007 09:01 PM |
| Any Body in Japan? | instruite | Chit-Chat | 0 | 4th August 2005 02:40 AM |
| Hello, Hi i am new, can any body help | jimsonpaul | General Electronics Chat | 2 | 10th February 2004 12:30 AM |
| Do any body know where can i buy a PIC SLOT? | mikemikemike | Electronic Projects Design/Ideas/Reviews | 2 | 15th December 2003 05:23 PM |