PIC simulator IDE + i2c EEPROM 24LC256

Ahoj,
pouzivate nekdo tento soft?
Potreboval bych radu:
Nedari se mi zapisovat a cist do/z i2c EEPROM (v realu, v simulaci neni problem).
Do PICu jsem zkusil zapsat priklad “EXAMPLE 8: I2C communication with 24c256 eeprom” ( oshonsoft.com/picexamples.html ), bohuzel to nejak nejde. Porad to cte 255.
Nevite nekdo, kde je finta? Trochu tusim, ze by mohla byt zrada v konfiguraci SSPCON, SSPADD atd., v programu to nikde nevidim, ale fakt nevim. ASM bohuzel vubec nerozumim.
Diky moc za pripadne rady.

PIC Basic sice neumím, ale pro čtení z EEPROM by to možná mělo být takhle

Takze:
SSPSTAT = 0x80
SSPCON = 0x28 (to jsem zkousel uz predtim, podle datasheetu, a nic)
SSPADD = 0X28 (mam tam misto 12MHz 4MHz krystal)

Porad to nechce nic delat, porad cte (zobrazuje) 255

v Basic Compileru mam toto:

[code]Define CONF_WORD = 0x3f72
Define CLOCK_FREQUENCY = 4

AllDigital

Define LCD_BITS = 8
Define LCD_DREG = PORTD
Define LCD_DBIT = 0
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 1
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 2
Define LCD_EREG = PORTA
Define LCD_EBIT = 3
Define LCD_READ_BUSY_FLAG = 1

PORTA = 0
PORTD = 0

OPTION_REG = 0x00
SSPCON = 0x28
SSPSTAT = 0x80
SSPADD = 0x28

TRISB = 0x1f

Symbol sda = PORTC.4
Symbol scl = PORTC.3

Dim addr As Word
Dim data As Byte

Lcdinit

For addr = 0 To 31
Lcdcmdout LcdClear
data = 255 - addr
I2CWrite sda, scl, 0xa0, addr, data
Lcdout “Write To EEPROM”
Lcdcmdout LcdLine2Home
Lcdout “(”, #addr, ") = ", #data
WaitMs 100
Next addr

For addr = 0 To 31
Lcdcmdout LcdClear
I2CRead sda, scl, 0xa1, addr, data
Lcdout “Read From EEPROM”
Lcdcmdout LcdLine2Home
Lcdout “(”, #addr, ") = ", #data
WaitMs 100
Next addr

[/code]

Assembler to vyplodi takto:

; Compiled with: PIC Simulator IDE v6.73 ; Microcontroller model: PIC16F877A ; Clock frequency: 4.0 MHz ; Begin R0L EQU 0x20 R0H EQU 0x21 R1L EQU 0x22 R1H EQU 0x23 R2L EQU 0x24 R2H EQU 0x25 R3L EQU 0x26 R3H EQU 0x27 R4L EQU 0x28 R4H EQU 0x29 R5L EQU 0x2A R5H EQU 0x2B SCL_PORT EQU 0x2C SCL_BIT EQU 0x2D SDA_PORT EQU 0x2E SDA_BIT EQU 0x2F ORG 0x0000 BCF PCLATH,3 BCF PCLATH,4 GOTO L0001 ORG 0x0004 RETFIE L0001: ; 1: Define CONF_WORD = 0x3f72 ; 2: Define CLOCK_FREQUENCY = 4 ; 3: ; 4: AllDigital BSF STATUS,RP0 MOVLW 0x06 MOVWF 0x1F MOVLW 0x07 MOVWF 0x1C ; 5: ; 6: Define LCD_BITS = 8 ; 7: Define LCD_DREG = PORTD ; 8: Define LCD_DBIT = 0 ; 9: Define LCD_RSREG = PORTA ; 10: Define LCD_RSBIT = 1 ; 11: Define LCD_RWREG = PORTA ; 12: Define LCD_RWBIT = 2 ; 13: Define LCD_EREG = PORTA ; 14: Define LCD_EBIT = 3 ; 15: Define LCD_READ_BUSY_FLAG = 1 ; 16: ; 17: PORTA = 0 BCF STATUS,RP0 CLRF 0x05 ; 18: PORTD = 0 CLRF 0x08 ; 19: ; 20: OPTION_REG = 0x00 BSF STATUS,RP0 CLRF 0x01 ; 21: SSPCON = 0x28 BCF STATUS,RP0 MOVLW 0x28 MOVWF 0x14 ; 22: SSPSTAT = 0x80 BSF STATUS,RP0 MOVLW 0x80 MOVWF 0x14 ; 23: SSPADD = 0x28 MOVLW 0x28 MOVWF 0x13 ; 24: ; 25: TRISB = 0x1f MOVLW 0x1F MOVWF 0x06 ; 26: ; 27: Symbol sda = PORTC.4 ; The address of 'sda' is 0x7,4 ; 28: Symbol scl = PORTC.3 ; The address of 'scl' is 0x7,3 ; 29: BCF STATUS,RP0 ; 30: Dim addr As Word ; The address of 'addr' is 0x30 addr EQU 0x30 ; 31: Dim data As Byte ; The address of 'data' is 0x32 data EQU 0x32 ; 32: ; 33: Lcdinit BCF 0x05,3 BCF 0x05,1 BCF 0x05,2 BSF STATUS,RP0 BCF 0x05,3 BCF 0x05,1 BCF 0x05,2 CLRF 0x08 BCF STATUS,RP0 MOVLW 0x64 MOVWF R0L MOVLW 0x00 MOVWF R0H CALL W001 MOVLW 0x33 CALL LC02 MOVLW 0x33 CALL LC02 MOVLW 0x33 CALL LC02 MOVLW 0x38 CALL LC02 MOVLW 0x0C CALL LC02 MOVLW 0x01 CALL LC02 ; 34: ; 35: For addr = 0 To 31 CLRF 0x30 CLRF 0x31 L0002: MOVF 0x30,W MOVWF R0L MOVF 0x31,W MOVWF R0H CLRF R1H MOVLW 0x1F CALL C006 BTFSS STATUS,Z GOTO L0003 ; 36: Lcdcmdout LcdClear MOVLW 0x01 CALL LC02 ; 37: data = 255 - addr ; The address of 'oshonsoft_temp_1' is 0x33 oshonsoft_temp_1 EQU 0x33 MOVF 0x30,W SUBLW 0xFF MOVWF 0x33 MOVF 0x31,W BTFSS STATUS,C ADDLW 0x01 SUBLW 0x00 MOVWF 0x34 MOVF 0x33,W MOVWF 0x32 ; 38: I2CWrite sda, scl, 0xa0, addr, data MOVLW 0x07 MOVWF SDA_PORT MOVLW 0x10 MOVWF SDA_BIT BSF STATUS,RP0 BCF TRISC,4 BCF STATUS,RP0 MOVLW 0x07 MOVWF SCL_PORT MOVLW 0x08 MOVWF SCL_BIT BSF STATUS,RP0 BCF TRISC,3 BCF STATUS,RP0 CALL IC41 CALL IC41 CALL IC31 MOVLW 0xA0 CALL IC01 MOVF 0x31,W CALL IC01 MOVF 0x30,W CALL IC01 MOVF 0x32,W CALL IC01 CALL IC41 ; 39: Lcdout "Write To EEPROM" MOVLW 0x57 CALL LC01 MOVLW 0x72 CALL LC01 MOVLW 0x69 CALL LC01 MOVLW 0x74 CALL LC01 MOVLW 0x65 CALL LC01 MOVLW 0x20 CALL LC01 MOVLW 0x54 CALL LC01 MOVLW 0x6F CALL LC01 MOVLW 0x20 CALL LC01 MOVLW 0x45 CALL LC01 MOVLW 0x45 CALL LC01 MOVLW 0x50 CALL LC01 MOVLW 0x52 CALL LC01 MOVLW 0x4F CALL LC01 MOVLW 0x4D CALL LC01 ; 40: Lcdcmdout LcdLine2Home MOVLW 0xC0 CALL LC02 ; 41: Lcdout "(", #addr, ") = ", #data MOVLW 0x28 CALL LC01 MOVF 0x30,W MOVWF R2L MOVF 0x31,W MOVWF R2H CALL LC21 MOVLW 0x29 CALL LC01 MOVLW 0x20 CALL LC01 MOVLW 0x3D CALL LC01 MOVLW 0x20 CALL LC01 MOVF 0x32,W MOVWF R2L CLRF R2H CALL LC21 ; 42: WaitMs 100 MOVLW 0x64 MOVWF R0L CLRF R0H CALL W001 ; 43: Next addr MOVLW 0x01 ADDWF 0x30,F MOVLW 0x00 BTFSC STATUS,C ADDLW 0x01 BTFSC STATUS,C GOTO L0003 ADDWF 0x31,F BTFSS STATUS,C GOTO L0002 L0003: MOVLW 0x1F ANDWF STATUS,F ; 44: ; 45: For addr = 0 To 31 CLRF 0x30 CLRF 0x31 L0004: MOVF 0x30,W MOVWF R0L MOVF 0x31,W MOVWF R0H CLRF R1H MOVLW 0x1F CALL C006 BTFSS STATUS,Z GOTO L0005 ; 46: Lcdcmdout LcdClear MOVLW 0x01 CALL LC02 ; 47: I2CRead sda, scl, 0xa1, addr, data MOVLW 0x07 MOVWF SDA_PORT MOVLW 0x10 MOVWF SDA_BIT BSF STATUS,RP0 BCF TRISC,4 BCF STATUS,RP0 MOVLW 0x07 MOVWF SCL_PORT MOVLW 0x08 MOVWF SCL_BIT BSF STATUS,RP0 BCF TRISC,3 BCF STATUS,RP0 CALL IC41 CALL IC41 CALL IC31 MOVLW 0xA0 CALL IC01 MOVF 0x31,W CALL IC01 MOVF 0x30,W CALL IC01 CALL IC41 CALL IC31 MOVLW 0xA1 CALL IC01 CALL IC11 MOVWF 0x32 CALL IC41 ; 48: Lcdout "Read From EEPROM" MOVLW 0x52 CALL LC01 MOVLW 0x65 CALL LC01 MOVLW 0x61 CALL LC01 MOVLW 0x64 CALL LC01 MOVLW 0x20 CALL LC01 MOVLW 0x46 CALL LC01 MOVLW 0x72 CALL LC01 MOVLW 0x6F CALL LC01 MOVLW 0x6D CALL LC01 MOVLW 0x20 CALL LC01 MOVLW 0x45 CALL LC01 MOVLW 0x45 CALL LC01 MOVLW 0x50 CALL LC01 MOVLW 0x52 CALL LC01 MOVLW 0x4F CALL LC01 MOVLW 0x4D CALL LC01 ; 49: Lcdcmdout LcdLine2Home MOVLW 0xC0 CALL LC02 ; 50: Lcdout "(", #addr, ") = ", #data MOVLW 0x28 CALL LC01 MOVF 0x30,W MOVWF R2L MOVF 0x31,W MOVWF R2H CALL LC21 MOVLW 0x29 CALL LC01 MOVLW 0x20 CALL LC01 MOVLW 0x3D CALL LC01 MOVLW 0x20 CALL LC01 MOVF 0x32,W MOVWF R2L CLRF R2H CALL LC21 ; 51: WaitMs 100 MOVLW 0x64 MOVWF R0L CLRF R0H CALL W001 ; 52: Next addr MOVLW 0x01 ADDWF 0x30,F MOVLW 0x00 BTFSC STATUS,C ADDLW 0x01 BTFSC STATUS,C GOTO L0005 ADDWF 0x31,F BTFSS STATUS,C GOTO L0004 L0005: MOVLW 0x1F ANDWF STATUS,F ; 53: ; 54: ; 55: ; 56: ; End of program L0006: GOTO L0006 ; Division Routine D001: MOVLW 0x10 MOVWF R3L CLRF R2H CLRF R2L D002: RLF R0H,W RLF R2L,F RLF R2H,F MOVF R1L,W SUBWF R2L,F MOVF R1H,W BTFSS STATUS,C INCFSZ R1H,W SUBWF R2H,F BTFSC STATUS,C GOTO D003 MOVF R1L,W ADDWF R2L,F MOVF R1H,W BTFSC STATUS,C INCFSZ R1H,W ADDWF R2H,F BCF STATUS,C D003: RLF R0L,F RLF R0H,F DECFSZ R3L,F GOTO D002 MOVF R0L,W RETURN ; Comparison Routine C001: MOVWF R1L MOVLW 0x05 GOTO C007 C002: MOVWF R1L MOVLW 0x02 GOTO C007 C003: MOVWF R1L MOVLW 0x06 GOTO C007 C004: MOVWF R1L MOVLW 0x03 GOTO C007 C005: MOVWF R1L MOVLW 0x04 GOTO C007 C006: MOVWF R1L MOVLW 0x01 GOTO C007 C007: MOVWF R4L MOVF R1H,W SUBWF R0H,W BTFSS STATUS,Z GOTO C008 MOVF R1L,W SUBWF R0L,W C008: MOVLW 0x04 BTFSC STATUS,C MOVLW 0x01 BTFSC STATUS,Z MOVLW 0x02 ANDWF R4L,W BTFSS STATUS,Z MOVLW 0xFF RETURN ; Waitms Routine W001: MOVF R0L,F BTFSC STATUS,Z GOTO W002 CALL W003 DECF R0L,F NOP NOP NOP NOP NOP GOTO W001 W002: MOVF R0H,F BTFSC STATUS,Z RETURN CALL W003 DECF R0H,F DECF R0L,F GOTO W001 W003: MOVLW 0x0C MOVWF R2H W004: DECFSZ R2H,F GOTO W004 NOP NOP MOVLW 0x12 MOVWF R1L W005: DECFSZ R1L,F GOTO W006 CALL W007 CALL W007 NOP NOP RETURN W006: CALL W007 GOTO W005 W007: MOVLW 0x0D MOVWF R2L W008: DECFSZ R2L,F GOTO W008 NOP RETURN ; Waitus Routine - Byte Argument X001: MOVLW 0x0A SUBWF R4L,F BTFSS STATUS,C RETURN GOTO X002 X002: MOVLW 0x06 SUBWF R4L,F BTFSS STATUS,C RETURN GOTO X002 ; Waitus Routine - Word Argument Y001: MOVLW 0x10 SUBWF R4L,F CLRW BTFSS STATUS,C ADDLW 0x01 SUBWF R4H,F BTFSS STATUS,C RETURN GOTO Y002 Y002: MOVLW 0x0A SUBWF R4L,F CLRW BTFSS STATUS,C ADDLW 0x01 SUBWF R4H,F BTFSS STATUS,C RETURN GOTO Y002 ; Lcdout Routine LC01: BSF 0x05,1 BCF 0x05,2 MOVWF 0x08 CALL LCX1 BCF 0x05,1 BSF 0x05,2 BSF STATUS,RP0 COMF 0x08,F BCF STATUS,RP0 LC10: CALL LCX2 MOVWF R4L BTFSC R4L,7 GOTO LC10 BSF STATUS,RP0 CLRF 0x08 BCF STATUS,RP0 RETURN LCX1: BSF 0x05,3 NOP BCF 0x05,3 NOP RETURN LCX2: BSF 0x05,3 NOP MOVF 0x08,W BCF 0x05,3 NOP RETURN ; Lcdcmdout Routine LC02: BCF 0x05,1 BCF 0x05,2 MOVWF 0x08 CALL LCX1 BCF 0x05,1 BSF 0x05,2 BSF STATUS,RP0 COMF 0x08,F BCF STATUS,RP0 LC11: CALL LCX2 MOVWF R4L BTFSC R4L,7 GOTO LC11 BSF STATUS,RP0 CLRF 0x08 BCF STATUS,RP0 RETURN ; Lcdout Decimal Conversion Routine LC21: BSF R3H,7 MOVLW 0x27 MOVWF R1H MOVLW 0x10 CALL LC22 MOVLW 0x03 MOVWF R1H MOVLW 0xE8 CALL LC22 CLRF R1H MOVLW 0x64 CALL LC22 CLRF R1H MOVLW 0x0A CALL LC22 MOVF R2L,W GOTO LC23 LC22: MOVWF R1L MOVF R2H,W MOVWF R0H MOVF R2L,W MOVWF R0L CALL D001 MOVF R0L,W BTFSS STATUS,Z BCF R3H,7 BTFSC R3H,7 RETURN LC23: ADDLW 0x30 CALL LC01 RETURN ; I2CWrite Routine IC01: MOVWF R0L MOVLW 0x08 MOVWF R0H IC02: RLF R0L,F BTFSC STATUS,C CALL IC20 BTFSS STATUS,C CALL IC21 CALL IC22 CALL IC23 DECFSZ R0H,F GOTO IC02 CALL IC24 CALL IC03 CALL IC25 CALL IC21 RETURN IC03: CALL IC22 MOVF SDA_PORT,W MOVWF FSR MOVF SDA_BIT,W ANDWF INDF,W ADDLW 0xFF CALL IC23 RETURN IC31: CALL IC21 CALL IC23 GOTO IC29 IC41: CALL IC22 CALL IC20 GOTO IC29 IC20: MOVF SDA_PORT,W MOVWF FSR MOVF SDA_BIT,W IORWF INDF,F GOTO IC28 IC21: MOVF SDA_PORT,W MOVWF FSR COMF SDA_BIT,W ANDWF INDF,F GOTO IC28 IC22: MOVF SCL_PORT,W MOVWF FSR MOVF SCL_BIT,W IORWF INDF,F GOTO IC28 IC23: MOVF SCL_PORT,W MOVWF FSR COMF SCL_BIT,W ANDWF INDF,F GOTO IC28 IC28: BSF FSR,7 COMF INDF,W BCF FSR,7 ANDWF INDF,F IC29: NOP NOP RETURN IC24: MOVF SDA_PORT,W MOVWF FSR BSF FSR,7 MOVF SDA_BIT,W IORWF INDF,F RETURN IC25: MOVF SDA_PORT,W MOVWF FSR BSF FSR,7 COMF SDA_BIT,W ANDWF INDF,F RETURN ; I2CRead Routine IC11: CALL IC24 MOVLW 0x08 MOVWF R0H IC12: CALL IC03 RLF R0L,F DECFSZ R0H,F GOTO IC12 CALL IC25 CALL IC20 CALL IC22 CALL IC23 CALL IC21 MOVF R0L,W RETURN IC13: CALL IC24 MOVLW 0x08 MOVWF R0H IC14: CALL IC03 RLF R0L,F DECFSZ R0H,F GOTO IC14 CALL IC25 CALL IC21 CALL IC22 CALL IC23 MOVF R0L,W RETURN ; Configuration word settings ORG 0x2007 DW 0x3F72 ; End of listing END

Muzes mi prosim napsat, proc je pro cteni adresa 0xa1 ?

Pokud by jste se nekdo kouknul i na to asm, byl bych rad. Asi to bude kravsky prelozeny, nicmene jine veci mi v tom fungujou dobre.

Diky moc

Protože read/write se nastavuje posledním bitem v adrese. 0 je WRITE a 1 je READ. A adresa je 0xA0 tak z toho usuzuji, že vlastně pořád zapisuješ, ale nečteš. Tak proto ta 0xA1.
Ale zkoušel jsem ten PIC simulátor z jejich stránek a ten program po nastavení LCD a EEPROM ukazuje jako v simulátoru správnou funkci. A je mu úplně jedno, jestli je tam 0xA0 nebo 0xA1.

A pro 4Mhz krystal a 400khz je SSPADD 0x01

Tak zase nic.

Zkousel jsem vselijak kombinovat adresy, SSPADD jsem nastavil na 0x01 a porad to stejne.

Musi byt chyba nekde v prekladu do asm, nebo jsem blbej, nebo nevim.

To,ze ti to vypisuje hodnotu 255 svedci o tom,ze komunikace I2C je v poradku. Kdyby nebyla,zakouslo by se to na startovaci podmince.Z toho usuzuji,ze EEPROMKa sice komunikuje,ale podle me neposle data,protoze je chyba v adresaci…Dal bych tam 12Mhz krystal,protoze hodnota v SSPADD je 0x01 a co si matne pamatuju,tak jsem eeprom na 4M a 400khz sice rozjel,ale byly s tim problemy.

Zitra to zkusim na nepajivem poli,pokud nepujdu hned z nocni na pivko :slight_smile: Mam sice displej 4x20 a EEPROMku tady snad taky nejakou najdu.

A jen tak preventivne,zmer si,jestli adresovaci piny jsou skutecne na GND.

Byl bych ti hrozne vdecny, kdyby jsi to vyzkousel a dal mi vedet. Nechci se spokojit s tim, ze bych pouzival jen interni EEPROM v PICu - 256 8b pozic je docela malo (na ukladani namerenych hodnot + nastaveni + kalibraci).
Ale na to pivko si klidne dojdi, ono se pak po nocni lip spi (vlastni zkusenost :smiley: )

Pivko bude až večer.

Tak tě musím zklamat. Mě to funguje normálně, z originálním programem z jejich stránek, bez toho přepisu 0xA1, akorát jsem změnil z 12Mhz na 20Mhz. Zapíše hodnoty 255 - 224 a zase je zpětně přečte a pak se program zastaví na GOTO $.

Ale mám 20Mhz krystal, a všiml jsem si, že ve schématu chybí pul-up odpory 4k7 na SCL a SDA. Bez nich to fungovat nebude!! Já teď po ránu na ně taky zapoměl a taky mi to nešlo, až na po druhé.

Tak to mi z toho asi hrabne.
Pull-upy tam mam, trapil jsem to s krystalem 4MHz i s 12MHz a porad nic. 20MHz budu muset nekde koupit, ale stejne mi to nejde do hlavy.
Mozna by stacilo, aby to jelo na 100kHz (ta I2C), s krystalem 12MHz. Zmena casovani I2C se dela taky zmenou SSPADD?

Jeste otazka - jakou jsi pouzil pamet?

Na Xtale asi zalezat nebude (okrem casovych sluciek, ak tam nejake su - nestudoval som, ale i tak bude pomalsia frekvencia skor na prospech rozchodenia komunikacie). I2C, tak ako SPI je synchronna zbernica. Skor to bude tak, ze cim pomalsia frekvencia, tym skor to rozchodis, ak su na pricine velke parazitne kapacity s velkymi hodnotami pull-upov. Vrati Ti EEPROM ACK po prjati prveho bajtu? Ak nie, ani neskumaj preco data neposiela spat, ale preco je pre nu uvodny bajt neakceptovatelny. Ak Ti chodi ACK, potom bude problem v tej adresacii, alebo nedobrej sekvencii pri prechode zo zapisu adresy do poziadavky na nacitanie udajov z EEPROM. Daj vediet, ako si dopadol.

Tak teď jsem to nějak nepochopil.

Přidal jsem do programu [code]SSPCON = 0x0
SSPSTAT = 0x0
SSPADD = 0x0

For addr = 0 To 31
Lcdcmdout LcdClear
Lcdout #SSPADD, " ", #SSPSTAT, " ", #SSPCON
I2CRead sda, scl, 0xa0, addr, data
Lcdcmdout LcdLine2Home
Lcdout “(”, #addr, ") = ", #data,
WaitMs 500

[/code]

aby mi vypisoval hodnoty registrů SSPADD, SSPSTAT a SSPCON a je mi záhadou, že když hodnoty nenastavim a nechám je na programu, aby si je nastavil sám, tak jsou všude 0x00 a funguje to, když nastavím viz níže, tak to nejede. I když je to BLBOST, protože SSPCON 0x28 zapíná I2C v režimu master a Fosc/(4x(SSPADD+1)

SSPADD Fosc/(4x(SSPADD+1) nastavuje rychlost I2C, 100k,400k a 1M.Nemůže být 0x00.Možná by to vyšlo při nějaké hodnotě krystalu. SSPSTAT 0x80 nastavuje režim posílaní dat. U tohoto může být 0x00.

Asi to chce to pivo.

EPPROM mám 24FC1025, jsou na tom skoro stejně kromě bitu B0, ktrerej vybírá stránku, nemá vliv v tomto případě. Jedinej rozdíl, kromě velikosti je v tom, že tahle podporuje 1M rychlost.

A když dám do programuSSPCON = 0x28 SSPSTAT = 0x80 SSPADD = 0x0b tak se hodnoty na displeji zobrazí, sice v DEC, ale to je jedno. Takže si program adresy registru nepřepisuje.

Je mi zahádaou, jak to že to s 0x00 všude funguje.

EDIT:A když dám

SSPCON = 0x00 SSPSTAT = 0x80 SSPADD = 0x31 nebo 0x04 ,tak to jede na 100k i na 1Mb rychlost s krystalem 20Mhz. Takže “asi” SSPCON musí být 0x00. Ale jestli skutečně jede na 100k,400k nebo 1M asi nezjistím. DIVNÉ. Zlatej assembler

A dál už testovat nemůžu, vypršela demoverze PIC Basic

Tak ted jsem uplne mimo:

Prijdu z prace, vytocenej (cely den na to myslim), s planem, jak budu po PICu lovit bity nejakeho registru pro rizeni I2C. Sednu k tomu, pridam si na displej stav registru (diky za tip), zmenim zpozdeni (abych to stihal cist), odriznu nastaveni registru (necham program, at dela, co (snad) umi), nahraju a cumim, cumim a cumim.
Ono to JEDE!!!
Registry to sice ukazuje jako 0 0 0 (?)
Ale CTE!!!

Tak ted se pokusim o neco slozitejsiho (rad bych zapisoval a cetl 10bit hodnotu prevodniku do/z EE - takze zkusim zapisovat data.HI, data LO).

Diky Vam vsem za pomoc (i kdyz to jeste nemam v hlave srovnane, jak se to podarilo…)

Jo, jeste ten list:

[code]Define CONF_WORD = 0x3f72
Define CLOCK_FREQUENCY = 12

AllDigital

Define LCD_BITS = 8
Define LCD_DREG = PORTD
Define LCD_DBIT = 0
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 1
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 2
Define LCD_EREG = PORTA
Define LCD_EBIT = 3
Define LCD_READ_BUSY_FLAG = 1

PORTA = 0
PORTD = 0

OPTION_REG = 0x00
'SSPCON = 0x28
'SSPSTAT = 0x80
'SSPADD = 0x09

TRISB = 0x1f

Symbol sda = PORTC.4
Symbol scl = PORTC.3

Dim addr As Word
Dim data As Byte

Lcdinit

For addr = 0 To 31
Lcdcmdout LcdClear
data = 255 - addr
I2CWrite sda, scl, 0xa0, addr, data
Lcdout “Write To EEPROM”
Lcdcmdout LcdLine2Home
Lcdout “(”, #addr, ") = ", #data
WaitMs 100
Next addr

For addr = 0 To 31
Lcdcmdout LcdClear
I2CRead sda, scl, 0xa1, addr, data
Lcdout “Read From EEPROM”
Lcdcmdout LcdLine2Home
Lcdout “(”, #addr, ") = ", #data, #SSPADD, " ", #SSPSTAT, " ", #SSPCON
WaitMs 300
Next addr
[/code]

To pivo si asi dam taky