PDA

View Full Version : Intrc Pic16f88



Toley00
- 1st June 2006, 20:02
I have a program with a 16F88 at 4MHz internal osc that work but have some little bugs with the serial communication (I have try almost all serial speed). I suspect the internal clock is not accurate so I have build a simple prog to test the INTRC_CLKOUT and adjust it via the OSCTUNE register, but I can't see any clock output at RA6 with an oscilloscope. Here's my test program :

DEFINE OSC 4
@ __CONFIG _CONFIG1,_INTRC_CLKOUT&_PWRTE_ON&_MCLR_OFF&_ etc....
OSCCON = $6E
ANSEL = $00
CMCON = $07
OPTION_REG = %10000000

LED VAR PORTB.4
TEMP1 VAR BYTE

TRISA = %10111111
TRISB = %11101111
LED = 0

START :
LED = ~LED
PAUSE 500
GOTO START


Thank you if you have any idea

mister_e
- 1st June 2006, 20:50
How about


@ __CONFIG _CONFIG1, _INTRC_IO & _DEBUG_OFF & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _PWRTE_ON & _WDT_OFF
OSCCON=$60
TRISB=0

Start:
Toggle PORTB.4
pause 500
goto start

Toley00
- 2nd June 2006, 03:03
Thank you mister_e.

I think I didn't understood well the last bits of the OSCCON register but now it's ok. Sometimes it's too simple to understand the first time lolll. Now I've tune my internal oscillator to exactly 1.000 MHz (1/4 fosc) but my communication problem is still there (problably another thing I didn't understood). I seems to be a newbie but I do PicBasic Pro and assembly programming since some years but as a hobbyist.

OK here's my problem with some code exemple. I have 2 PIC, a 16F88 act as the master 4MHz INTRC and a 16F877A as a slave 4MHz XT, they communicate in serial at 2400 Baud. First the master send a 2 byte command to the slave who answer with a 2 string of 16 bytes to be print on a LCD.

The problem is that it never work the first time! Usually when the command is send, it return only strings of 0. After 2, 3 or more times the command is send, the slave return the correct strings of data. That's why I first think it's a speed problem but it's not.

Here's some piece of code :
After the push of a button the master do this

IDENT :
SEROUT2 PINOUT,396,["II"] 'Envois le code ASCII "II"
SERIN2 PININ,396,100,ABSENT,[STR VAL01\16] 'Si pas reponse en 100ms
SERIN2 PININ,396,[STR VAL02\16] 'va a absent
LCDOUT $FE,1,STR VAL01\16 'affiche la reponse du module
LCDOUT $FE,$C0,STR VAL02\15,"." 'ID caché remplacé par un.
SELECT CASE VAL02[15]
CASE $00,$01,$10,$11
PINMAX = 24
CASE ELSE
GOTO ABSENT
END SELECT
GOSUB PAU2S
RETURN
ABSENT :
LCDOUT $FE,1,"Veillez ins",$00,"rer" 'message si module absent
LCDOUT $FE,$C0,"un module SVP"
GOSUB PAU2S
RETURN


The code for the slave is :

START :
SERIN2 PININ,396,[VAL1,VAL2]
IF VAL1 = "I" THEN GOTO IDENT
IF VAL1 = "X" THEN GOTO MESURE
GOTO START

IDENT :
PAUSE 100
SEROUT2 PINOUT,396,["DIP 40 broches "]
PAUSE 100
SEROUT2 PINOUT,396,["Dessus v.1 S.T",$00]
GOTO START


Do I have to put pullup or pulldown resistor for serial communication between 2 Pic ?
If you see anything wrong in my code please let me know. Thank you

Sorry comments are in french but I think mister_e can read them.

mister_e
- 2nd June 2006, 03:10
Bien sur que je peut lire et comprendre le tout mon ami :D

I'm not going to tell you the answer... but you'll discover it by yourself. Before sending the First set of Byte, use your voltmeter and measure the voltage on your PINOUT pin.

Now measure it again when a few byte are sent and your PIC is waiting to send other byte.

Where's the difference? Now place a HIGH or LOW PINOUT at the top of your code, then a PAUSE 50 ( or something like that)

What's happening now?

Also be carefull about the Idle state of you PININ. It must met the according level in case no module are insert in the Dip socket. Use pull-up or pull-down to solve it.

Bonne chance!



LCDOUT $FE,1,"Veillez ins",$00,"rer" 'message si module absent
Veillez ou Veuillez :D ?

Toley00
- 2nd June 2006, 03:37
Thank you very much mister_e. Now it works as I want.

Thank you also for the french spelling... But you also have a spelling mistake, You should be called master_e.

mister_e
- 2nd June 2006, 03:46
The initial idea of Mister E (wich is also the name of my company) was mostely a kind of game with words to have many different meaning.

Mister E
Mistery

Funny that many of my french customer read the Invoice or Business card as mistere and still call me like that :D (mistere in french = Mistery for those who don't know french)

On the phone it's not even better... Mister E... no... not Mistery ... Mister E... M-I-S-T-E-R space E

anyways.. Off topic :D

Great to know it's working now!