I am using the pic12f683
Additionally variable addr must be a word not a byte!Code:i2cread sda, scl, cont, addr, val i2cread sda, scl, cont, addr,[val]
Al.
All progress began with an idea
I changed TRISIO, put brackets around the [val] variable and changed addr to a word sized variable .When I start up the microcontroller it sends the first serial out command to the computer but when I send a serial command to the microcontroller from the pc the microcontroller goes into a loop and repeats the first serial command non stop until I disconnect the power.
Code:define OSC 4 Define CHAR_PACING 1000 CMCON0 = 7 ANSEL = %00000000 TRISIO = %00000010 cont con %10100000 scl var GPIO.5 sda var GPIO.4 sout var GPIO.2 sein var GPIO.1 addr var word wr var byte val var byte Main: serout sout, 6, ["To write to EEPROM press w", 13, "To read EEPROM press r", 13] serin sein, 6, wr if (wr = "w") then goto ewrite if (wr = "r") then goto eread goto main ewrite: serout sout, 6, ["Write", 13] serout sout, 6, ["Enter address 0 - 15", 13] serin sein, 6, addr serout sout, 6, ["Enter value 0 - 255", 13] serin sein, 6, val i2cwrite sda, scl, cont, addr, [val] pause 10 serout sout, 6, ["Write complete", 13] goto main eread: serout sout, 6, ["Read", 13] serout sout, 6, ["Enter address 0 - 15", 13] serin sein, 6, addr i2cread sda, scl, cont, addr, [val] pause 10 serout sout, 6, [#val, 13] serout sout, 6, ["Read complete", 13] goto main
Last edited by Archangel; - 24th February 2010 at 03:56.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Since you made variable addr a word then you have to change your serin command to receive two bytes to be combined into one word. This means you have to Tx two bytes (SERIN is unable to receive word)
Al.Code:serin sein, 6, addr serin sein, 6, addr.byte0,addr.byte1
Last edited by aratti; - 24th February 2010 at 19:15.
All progress began with an idea
I have decided to narrow it down just to the SERIN command. I made a program to read the serial command from the pc and then transmit it back to the pc. When I send the serial data to the pic the transmit light flashes so I know the pc is sending the serial data but the pic is not retransmitting it back to the pc. I am using the debug terminal from the basic stamp program and Parallax USB2SER Development Tool.
Code:val var byte TRISIO = %00000010 main: serin GPIO.1, 6, [val] pause 10 serout GPIO.2, 6, [val] pause 10 goto main
SERIN doesn't need square bracket. Within bracket you will place the qualifier, not the variable.
Al.Code:serin GPIO.1, 6, [val] serin GPIO.1, 6, val
Last edited by aratti; - 24th February 2010 at 21:01.
All progress began with an idea
Bookmarks