PDA

View Full Version : Hserout



mazytis
- 17th May 2015, 02:07
Hi,
I need to do serial output with PIC12F675 using HSEROUT.

It's possible?

Sorry for my English speech.

richard
- 17th May 2015, 03:35
no get a 12f1822

Charlie
- 17th May 2015, 13:09
Or just use SEROUT (no "H")

Archangel
- 17th May 2015, 17:48
Or use the DEBUG function, usually makes smaller code.

mazytis
- 17th May 2015, 18:38
I just used SEROUT. :)

mazytis
- 20th May 2015, 00:43
Firstly I want to apologise for my English speech.
What's wrong with my code? Receiver will not turning on LED, when transmitter sending command.

Transmitter:


#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF & _MCLRE_OFF & _BODEN_OFF & _PWRTE_OFF
#ENDCONFIG
DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
DEFINE SER_BAUD 1200
DEFINE SER_CLROERR 1


CMCON = 7 : TRISIO = %00010001 : ADCON0.7 = 1 : ANSEL = %00011001


LED var GPIO.2
i var byte
Akumuliatorius VAR word
Lygis var word
Buves var word : Buves = 0
Buves1 var word
Buves2 var word


Adr1 var byte : Adr1 = %00111110
Adr2 var byte : Adr2 = %01101110
CMD1 VAR BYTE : cmd1 = %10111110
CMD2 var byte : cmd2 = %10011100
pause 100


FOR i = 1 TO 3
high led : pause 400
low led : pause 400
NEXT i

main:
ADCIN 0, akumuliatorius


if akumuliatorius <= 640 then
high led
else
low led
endif


adcin 3, lygis


Buves1 = Buves - 4 : Buves2 = Buves + 4


if Lygis <= Buves1 or Lygis >= Buves2 then
buves = lygis
SEROUT2 GPIO.1,813,[Adr1,Adr2,Lygis,CMD1,CMD2]
endif


goto main
end


Receiver:


#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF & _MCLRE_OFF & _BODEN_OFF & _PWRTE_OFF
#ENDCONFIG
DEFINE OSC 4
DEFINE SER_BAUD 1200
DEFINE SER_CLROERR 1


CMCON = 7 : TRISIO = %00100000


LED var GPIO.0
i var byte


Adr1 var byte : Adr1 = %00111110
Adr2 var byte : Adr2 = %01101110
CMD1 VAR BYTE
CMD2 var byte
Lygis var word
pause 100


FOR i = 1 TO 3
high led : pause 400
low led : pause 400
NEXT i

main:
SERIN2 GPIO.5,813,[wait (Adr1,Adr2),Lygis,cmd1,cmd2]
pause 10
if cmd1 = %10111110 and cmd2 = %10011100 then
high led
else
low led
endif
pause 10
goto main
end

Aussie Barry
- 20th May 2015, 02:12
Hi Mazytis,

One quick observation with your receiver code - your "pause 10" time is incredibly short. I doubt you will actually be able to see the LED change status

Cheers
Barry
VK2XBP

richard
- 20th May 2015, 02:13
from the manual

SERIN2
is not supported on 12-bit core PIC MCUs due to RAM and stack
constraints

use serin

mazytis
- 20th May 2015, 13:23
Still not working... :/

Transmitter:


#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF & _MCLRE_OFF & _BODEN_OFF & _PWRTE_OFF
#ENDCONFIG
DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
DEFINE SER_BAUD 2400
DEFINE SER_CLROERR 1

CMCON = 7 : TRISIO = %00010001 : ADCON0.7 = 1 : ANSEL = %00011001
INCLUDE "modedefs.bas"

LED var GPIO.2
i var byte
Akumuliatorius VAR word
Lygis var word
Buves var word : Buves = 0
Buves1 var word
Buves2 var word

Adr1 var byte : Adr1 = %00111110
Adr2 var byte : Adr2 = %01101110
CMD1 VAR BYTE : cmd1 = %10111110
CMD2 var byte : cmd2 = %10011100
pause 100

FOR i = 1 TO 3
high led : pause 400
low led : pause 400
NEXT i

main:
ADCIN 0, akumuliatorius

if akumuliatorius <= 640 then
high led
else
low led
endif

adcin 3, lygis

Buves1 = Buves - 4 : Buves2 = Buves + 4

if Lygis <= Buves1 or Lygis >= Buves2 then
buves = lygis
SEROUT GPIO.1,T2400,[Adr1,Adr2,Lygis,CMD1,CMD2]
endif

goto main
end


Receiver:


#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF & _MCLRE_OFF & _BODEN_OFF & _PWRTE_OFF
#ENDCONFIG
DEFINE OSC 4
DEFINE SER_BAUD 2400
DEFINE SER_CLROERR 1

CMCON = 7 : TRISIO = %00100000
INCLUDE "modedefs.bas"

LED var GPIO.0
i var byte

Adr1 var byte
Adr2 var byte
CMD1 VAR BYTE
CMD2 var byte
Lygis var word
pause 100

FOR i = 1 TO 3
high led : pause 400
low led : pause 400
NEXT i

main:
SERIN GPIO.5,T2400,[Adr1,Adr2,Lygis,CMD1,CMD2]
if Adr1 = %00111110 and ADR2 = %01101110 and cmd1 = %10111110 and cmd2 = %10011100 then
high led : pause 100
else
low led
endif
goto main
end

richard
- 20th May 2015, 13:42
add a sync chr to the tx eg
SEROUT GPIO.1,T2400,["*",Adr1,Adr2,Lygis,CMD1,CMD2]

rx becomes

SERIN GPIO.5,T2400,["*"],Adr1,Adr2,Lygis,CMD1,CMD2


syntax for logical expressions is best done in parenthesis

if (Adr1 = %00111110) and (ADR2 = %01101110) and (cmd1 = %10111110 )and (cmd2 = %10011100) then



mazytis
- 20th May 2015, 15:50
Still the same. Maybe I don't configured something?

richard
- 21st May 2015, 03:10
you might have a rmw issue

try this



#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF & _MCLRE_OFF & _BODEN_OFF & _PWRTE_OFF
#ENDCONFIG
DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
DEFINE SER_BAUD 2400
DEFINE SER_CLROERR 1

CMCON = 7 : TRISIO = %00010001 : ADCON0.7 = 1 : ANSEL = %00011001
INCLUDE "modedefs.bas"

LED var GPIO.2
i var byte
Akumuliatorius VAR word
Lygis var word
Buves var word : Buves = 0
Buves1 var word
Buves2 var word

Adr1 var byte : Adr1 = %00111110
Adr2 var byte : Adr2 = %01101110
CMD1 VAR BYTE : cmd1 = %10111110
CMD2 var byte : cmd2 = %10011100
pause 100

FOR i = 1 TO 3
high led : pause 400
low led : pause 400
NEXT i

main:
ADCIN 0, akumuliatorius

if akumuliatorius <= 640 then
high led
else
low led
endif
gpio.0=1
adcin 3, lygis

Buves1 = Buves - 4 : Buves2 = Buves + 4

if Lygis <= Buves1 or Lygis >= Buves2 then
buves = lygis
SEROUT GPIO.1,T2400,["*",Adr1,Adr2,Lygis,CMD1,CMD2]
endif

goto main
end