Hi,
I need to do serial output with PIC12F675 using HSEROUT.
It's possible?
Sorry for my English speech.
Printable View
Hi,
I need to do serial output with PIC12F675 using HSEROUT.
It's possible?
Sorry for my English speech.
no get a 12f1822
Or just use SEROUT (no "H")
Or use the DEBUG function, usually makes smaller code.
I just used SEROUT. :)
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:
Receiver:Code:#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
Code:#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
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
from the manual
use serinQuote:
SERIN2
is not supported on 12-bit core PIC MCUs due to RAM and stack
constraints
Still not working... :/
Transmitter:
Receiver:Code:#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
Code:#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
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
Still the same. Maybe I don't configured something?
you might have a rmw issue
try this
Code:#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