PDA

View Full Version : IC2 pic 18f452 program problems



MrSafe
- 13th September 2007, 22:24
Hi

Hardware:

Pic 18f452
And I am trying to communicate and program a text to speed module.
Heres the link to the module.

http://www.picbasic.co.uk/forum/newthread.php?do=newthread&f=4

The link to the tech sheet for the device:

http://www.robot-electronics.co.uk/htm/Sp03doc.shtml

I am using the pl1 pint section to program the unit:

I use the SDA and SCL pins which connect to my pic.

I am unsure how to program this unit I have tried with no success and with the unability to get any response for it. The unit has a default message which plays when you turn it on. Which is "thank you for purchasing the sp03".

Heres my code that I am trying to use to talk with the unit:


'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : *
'* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/14/2007 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
'
'---- Defining Modefier 4 serial in/out ----
'
include "modedefs.bas"
'
'---- Defining Oscillator ----
'
define OSC 4 ; Using 4MHz Oscillator
'
'---- Defineing Ports ----
'
TRISB = $00
PORTB = $00
TRISD = $00
PORTB = $00
'
'---- Defining TX Variables ----
'
X var word
Y var word
'
'---- Defining Variables ----
'
DEFINE I2C_HOLD 1
define I2C_SLOW 1
'
'---- Starting Of Main Program ----
'
Main:
pause 4000
'
Start:
serout PORTD.0, T9600, [#80]
pause 100
'
serout PORTD.0, T9600, [#00]
pause 100
'
serout PORTD.0, T9600, [#04]
pause 100
'
serout PORTD.0, T9600, [#02]
pause 100
'
for x = 0 to 6 ; output the following
lookup x, [$68,$65,$6C,$6C,$6F,$00],y
serout PORTD.0, T9600, [y]
pause 10
next x
'
goto start
'
end


I have also uploaded a copy of my code in a text file for anyone who needs to download it.
All the fallowing code does is get the unit to say hello however I am unable to get it to say hello. I think first my programing code is wrong and two my hardware set up is wrong. Where do I connect the SDA pin to? and the SCL? do I simply connect the scl to a random pin on the pic? and the SDA to my data transmitting pin on the pic?

Darrel Taylor
- 14th September 2007, 09:26
Press F8 for MrSafe mode. :p

Well, for I2C, you would use I2CWRITE, instead of SEROUT.

The SDA and SCL can be on almost any pin. Just specify them in the I2CWRITE statement.

P.S. Don't forget the 4.7K Pull-ups on SDA and SCL.
<br>

GrandPa
- 14th September 2007, 20:08
Hi Darrel!



The SDA and SCL can be on almost any pin. Just specify them in the I2CWRITE statement.


I know you're right, but then what's is the purpose of having specific pins listed in the datasheet for SCL and SDA? (I'm using PIC184620)

Is there any difference between those pins and any others regarding I2C?


J-P

Darrel Taylor
- 14th September 2007, 23:42
The dedicated SCL/SDA pins are for the SSP (Synchronous Serial Port).
The SSP module can do SPI or I2C, in Master or Slave modes.

The I2CWRITE/I2CREAD are bit bang routines that don't use the Hardware SSP, so they can use almost any pin as SDA and SCL.

There aren't any PBP commands that use the SSP directly.
<br>

MrSafe
- 19th September 2007, 02:31
thank you I have solved it.

I have another problem I have a loop set up to where it sends messages out until the user presses a key.

example:



while key != 15

gosub getkey

serout PORTD.0, T1200, [X]

wend

To clarify this program sends data the first time but then waits for a user to press a key(other than 15) before sending the data again when it should send the data until the user presses a key (15).

Darrel Taylor
- 19th September 2007, 04:33
If your getkey subroutine doesn't return if no keys are pressed, it'll do what you are describing.

But it's hard to say whats wrong without seeing the getkey subroutine.
<br>

MrSafe
- 20th September 2007, 00:44
Heres the subroutine for get key




'---- Subroutine to Key from keypad ----
'
getkey:
;
key = 0
PortC = 0 ' all outputs pins low
TrisC = $f0 ' bottom 4 pins out, top 4 pins in
;
input PORTC
;
pause 250
;
PORTC = %11111110 ' row 1
;
if PORTC.4 = 0 then
key = 1
return
endif
;
if PORTC.5 = 0 then
key = 2
return
endif
;
if PORTC.6 = 0 then
key = 3
return
endif
;
if PORTC.7 = 0 then
key = 12
return
endif
;
PORTC = %11111101 ' row 2
;
if PORTC.4 = 0 then
key = 4
return
endif
;
if PORTC.5 = 0 then
key = 5
return
endif
;
if PORTC.6 = 0 then
key = 6
return
endif
;
if PORTC.7 = 0 then
key = 13
return
endif
;
PORTC = %11111011 ' row 3
;
if PORTC.4 = 0 then
key = 7
return
endif
;
if PORTC.5 = 0 then
key = 8
return
endif
;
if PORTC.6 = 0 then
key = 9
return
endif
;
if PORTC.7 = 0 then
key = 14
return
endif
;
PORTC = %11110111 ' row 4
;
if PORTC.4 = 0 then
key = 10
return
endif
;
if PORTC.5 = 0 then
key = 0
return
endif
;
if PORTC.6 = 0 then
key = 11
return
endif
;
if PORTC.7 = 0 then
key = 15
return
endif
;
goto getkey
return
;
gotkey:
key = (col * 4) + (ncd (row ^ $f))
'
return
'
end

Darrel Taylor
- 20th September 2007, 18:55
Comment out the goto getkey just before GotKey:

That will keep it from waiting for a key before proceeding.
<br>