PDA

View Full Version : cmcon with SEROUT2



mbw123
- 21st September 2006, 01:02
Greetings,

I am using a PIC16F628A and I am trying to send serial data using SEROUT2. My code basically is
--------------------------
cmcon =7

IF (PORTA.1 = 0) then pressed

goto main

pressed:

SEROUT2...(etc)
-------------------------
I am getting a compile error stating that SEROUT2 is invalid. I think it has something to do with "cmcon =7" because when I delete it it compiles correctly (I need the cmcon line because without it the button will not work). Any help is appreciated!

-Mike

mister_e
- 21st September 2006, 01:27
there's no chance it have something to do with CMCON. Check your SEROUT2 syntax or post your whole code here.

BTW, why are you using SEROUT2 when your PIC have a USART? HSEROUT on the right pins is far better.

mbw123
- 21st September 2006, 01:57
Ooops! I caught my incredibly stupid error (I didn't define the serial modes). Sorry for wasting your time, mister_e. I do have a question though. What are the benefits of using the hardware serial ports over SEROUT2? Thanks for your time.

-Mike

mister_e
- 21st September 2006, 02:22
Have a look there => http://www.picbasic.co.uk/forum/showthread.php?t=4681

Everything is covered and well explain.

The ONLY limitation, is that you have to use the dedicated pins of the USART... i never felt it was a limitation so far :D

mbw123
- 21st September 2006, 02:37
Ok, here is all my code. I will change the two lines concerning serout2 and serin2 with the hardware serial ports code. Basically this program just receives the button input, outputs the serial data (to itself; it is a test circut so don't bother asking why...) and supposedly receives the data and turns on the LED. It isn't working though. Thanks for the link to the HSEROUT/HSERIN page, by the way.

CODE:
-----------------------------

INCLUDE "modedefs.bas"

Pre CON $A5
Synch CON "~"

CMCON =7

main:
if (PORTB.1 = 0) then pressed

pressed:
serout2 PORTB.2, N2400, [Pre, Synch,"1"]
serin2 PORTB.3,N2400,[WAIT(Synch),in]
if (in == "1") then
high PORTB.4
pause 250
low OPRTB.4
pause 250
endif

-----------------------
Thank you very much for your help...

-Mike

mbw123
- 21st September 2006, 02:51
exclude the spelling errors from the code from my previous post...

mister_e
- 21st September 2006, 04:36
Hi,
Try this one and read carefully the SERIN2, SEROUT2 section about the baudrate stuff. You will also foind a table in appendix A for the various baudrate values


@ __CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON

TRISB = %11101011
CMCON = 7
Baud con 16780 ' 2400 bauds
Pre CON $A5
Synch CON "~"
In var byte

LOW PORTB.2 ' inverted mode normal idle state
pause 50

Main:
if (PORTB.1 = 0) then pressed
goto main

Pressed:
serout2 PORTB.2, baud, [Pre, Synch,"1"]
serin2 PORTB.3, baud, [WAIT(Synch),in]
if (in == "1") then
high PORTB.4
pause 250
low PORTB.4
pause 250
endif
goto main

mbw123
- 22nd September 2006, 00:52
I compiled your code but I got this error:

--> opcode expected instead of '__config'

Please help.

-Mike