View Full Version : Hserin
- 14th December 2008, 16:04
Hello,
I'm pulling my hair out, so I got on this forum hoping that someone could help me with my sanity.
I am trying to create a Christmas show with some boards that I built earlier this year. I am transmitting using xbees to onboard pics from a piece of software called vixen. Vixen transmits a string like the following:
In hex:
7E 80 00 FF 00 00 00 00 00 00 7E 81 00 00 FF 00 00 00 00 00 7E 82 ...
The 7E is some sort of like identifier and the 80, 81, and 82 are the "box" that the data is intended for. The following 8 hex values are then the brightnesses of each of the 8 channels on board.
I setup HSERIN like this:
HSERIN [wait($7E),wait($80),STR INP\8]
It seems to work fine, when the identifier is the last one in the string, so for the example above, my identifier would have to be $82 in order for the device to work correctly. In other words, the rest of my boxes with identifier 80 or 81 would not receive everything correctly.
Any help would be greatly appreciated!
Thanks,
Dave
Darrel Taylor
- 14th December 2008, 16:43
Receive 9 bytes to the array, and test for the "Box" code after receiving the data.
Maybe something like this...
HSERIN [wait($7E),STR INP\9]
SELECT CASE INP(0)
CASE $80
; The data for Box $80 is in INP(1 thru 8)
CASE $81
; The data is for Box $81
CASE $82
; The data is for Box $82
END SELECT
- 14th December 2008, 19:44
Thanks for the response.
I tried loading the 9 characters after the $7E, and then running it through the case statement and I get the same problems.
I tried sending back out serially what I am was loading into inp, and I realized that I think that actually it is receiving correctly, but in fact that it has something to do with the dimming. I don't know if anybody has the time to look at all of this, but I'll attach my code below and see if anybody catches anything that I'm not.
DEFINE HSER_RCSTA 90h ' Enable serial receive
DEFINE HSER_TXSTA 24h ' Enable serial transmit
SPBRG = 10
DEFINE HSER_CLROERR 1 'Clear Overflow Automatically
PIE1.5 = 1 ' Enable interrupt on USART
ADCON1 = %01111111
INTCON = %11000000
INTCON3 = %10010000
ON INTERRUPT GoTo Interupt ' Declare interrupt handler routine
INP VAR BYTE(9)
TMP VAR BYTE
LowTimer VAR BYTE
HighTimer VAR BYTE
HSEROUT ["Now Operating at 115.2KBps",10]
TRISA.0 = 0 'Channel 1 'Red
TRISA.1 = 0 'Channel 2
TRISA.2 = 0 'Channel 3
TRISA.3 = 0 'Channel 4
TRISB.3 = 0 'Channel 5 'Green
TRISB.2 = 0 'Channel 6
TRISB.7 = 0 'Channel 7
TRISB.6 = 0 'Channel 8
TRISB.0 = 0 'New Channel 8
TRISB.2 = 1 '120VAC Line In
PORTA.0 = 0
PORTA.1 = 0
Loop:
'String Reading and Brightness Adjustment
LowTimer = TMR0L
HighTimer = TMR0H
IF HighTimer = 0 THEN
IF INP(0) > LowTimer THEN
PORTA.0 = 1 'Channel 1
GOSUB TRIAC_PAUSE
PORTA.0 = 0
ENDIF
IF INP(1) > LowTimer THEN
PORTA.1 = 1 'Channel 2
GOSUB TRIAC_PAUSE
PORTA.1 = 0
ENDIF
IF INP(2) > LowTimer THEN
PORTA.2 = 1 'Channel 3
GOSUB TRIAC_PAUSE
PORTA.2 = 0
ENDIF
IF INP(3) > LowTimer THEN
PORTA.3 = 1 'Channel 4
GOSUB TRIAC_PAUSE
PORTA.3 = 0
ENDIF
LowTimer = TMR0L
HighTimer = TMR0H
IF INP(4) > LowTimer THEN
PORTB.3 = 1 'Channel 5
GOSUB TRIAC_PAUSE
PORTB.3 = 0
ENDIF
IF INP(5) > LowTimer THEN
PORTB.6 = 1 'Channel 6
GOSUB TRIAC_PAUSE
PORTB.6 = 0
ENDIF
IF INP(6) > LowTimer THEN
PORTB.7 = 1 'Channel 7
GOSUB TRIAC_PAUSE
PORTB.7 = 0
ENDIF
IF INP(7) > LowTimer THEN
PORTB.0 = 1 'Channel 8
GOSUB TRIAC_PAUSE
PORTB.0 = 0
ENDIF
ENDIF
Goto LOOp
DISABLE
Interupt:
IF INTCON3.1 = 1 THEN
TMR0H = 0
TMR0L = 0
T0CON = %10000110
INTCON3 = %10010000
ELSE
HSERIN [wait($7E),wait($80),STR INP\8]
INTCON = %11000000
ENDIF
Proceed:
Resume
Enable
triac_pause:
ASM
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
ENDASM
RETURN
END
Darrel Taylor
- 14th December 2008, 20:12
The USART settings indicate that you want to receive at 115200 baud, with the CPU running at 20Mhz.
But since there isn't an OSC defined, PBP defaults to 4Mhz, which would give you the wrong baudrate.
If you are actually running at 4Mhz, then the closest you can get to 115200, is 125000. That would be a SPBRG of 1.
ngeronikolos
- 15th December 2008, 20:57
Hello to everybody,
I have ALSO a problem with HSERIN(?).
My setup is CPU 16F627A internal OSC 4Mhz.I want to send via a termial(hyper or similar) a byte to pic.
The PIC reads the byte and it sends to the DS1620 Digital Thermometer and Thermostat.That is not working......
FOR EXAMPLE if i send via the termial the hex A1 (this is the InChar) I should have take an answer to the terminal with the stored value of high temperature limit.The DS1620 is working with the PIC.
BUT I CAN NOT FIND THE MISTAKE
HERE IS MY FULL CODE
--------------------------------------------------------
include "modedefs.bas"
@ DEVICE pic16F627A, INTRC_OSC_NOCLKOUT ' system clock options
@ DEVICE pic16F627A, WDT_ON ' watchdog timer
@ DEVICE pic16F627A, PWRT_ON ' power-on timer
@ DEVICE pic16F627A, MCLR_OFF ' master clear options (internal)
@ DEVICE pic16F627A, BOD_OFF ' brown-out detect
@ DEVICE pic16F627A, LVP_OFF ' low-voltage programming
@ DEVICE pic16F627A, CPD_OFF ' data memory code Protect
@ DEVICE pic16F627A, PROTECT_OFF ' program code protection
CMCON = 7 'Turn off comparators
VRCON = 0
INTCON = 0 ' Disable interrupts
' DEFINE VARIABLES FOR SERIAL TO PC 2400 8-N-1
;DEFINE NO_CLRWDT 1
DEFINE HSER_CLROERR 1 'Automatically clear over-run errors
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25
;DEFINE HSER_CLROERR 1
;DEFINE HSER_RCSTA 90H
;DEFINE HSER_TXSTA 20H
;DEFINE HSER_BAUD 2400
;DEFINE HSER_SPBRG 25
' DS1620 control pins
RST var PORTA.4 ' Reset pin
DQ var PORTA.2 ' Data pin
CLK var PORTA.3 ' Clock pin
INPUT PORTA.3
INPUT PORTA.4
' Allocate variables
temp var word ' Storage for temperature
InChar VAR byte
RCIF VAR PIR1.5
Low RST ' Reset the device
;-----------------------------------------------------------------
START:
While RCIF = 1
hserin 100,start,[InChar]
mainloop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee];Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, MSBFIRST, [InChar] ' Send read command
HSERout [InChar]
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
hserout [" Temp = ",dec (temp >> 1), ".", dec (temp.0 * 5)," oC",13]
Wend
Goto START ' Do it forever
End
-----------------------------------------------------------
PLEASE I need your advice
Thanks
Nikos
skimask
- 16th December 2008, 00:02
My setup is CPU 16F627A internal OSC 4Mhz.I want to send via a termial(hyper or similar) a byte to pic.
Use a 4Mhz crystal or resonator instead of the internal 4Mhz.
HERSIN/HSEROUT are clock sensitive. The DS1620...not so much...
ngeronikolos
- 16th December 2008, 08:54
I will try to add an external crystal BUT i do not think that this is the brpblem!!!!!!!!!!The echo sample code for HERSIN/HSEROUT is working...
Something else happend.When It reads the byte and trying to send to DS1620
(Shiftout).
mackrackit
- 16th December 2008, 12:54
I will try to add an external crystal BUT i do not think that this is the brpblem!!!!!!!!!!The echo sample code for HERSIN/HSEROUT is working...
Something else happend.When It reads the byte and trying to send to DS1620
(Shiftout).
Maybe you need to make the variable a number of some kind?
From the manual...
Modifier Operation
{I}{S}BIN{1..16} Send binary digits
{I}{S}DEC{1..5} Send decimal digits
{I}{S}HEX{1..4} Send hexadecimal digits
REP c\n Send character c repeated n times
STR ArrayVar{\n} Send string of n characters
ngeronikolos
- 16th December 2008, 15:24
Maybe you need to make the variable a number of some kind?
My variable is the InChar (look the code) and I set it as a byte.
The possible value could be $a1 or $a2 or $aa.
When I type that value via the terminal I have it back (hserout) but I do not have correct answer from the DS1620.
The strange thing is that I send
$a1
and I receive back
$
a
1
mackrackit
- 16th December 2008, 16:19
hserin 100,start,[WAIT($), HEX InChar]
Shiftout DQ, CLK, MSBFIRST, ["$",HEX InChar]
MAYBE????
Darrel Taylor
- 16th December 2008, 18:25
Do you have a Pull-Up resistor on PORTA.4 (RST)?
It's an Open Collector output, so it can't go HIGH on it's own.
<br>
ngeronikolos
- 16th December 2008, 18:49
Of course my friend Taylor I use Pull-Up resistor on PORTA.4...
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.