Corrected the errors, to level of my knowledge. Code compiles now, but it does not do anything. Here it is:
Code:
;----[16F1829 Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "16LF1829"
#DEFINE MCU_FOUND 1
#CONFIG
cfg1 = _FOSC_INTOSC ; INTOSC oscillator: I/O function on CLKIN pin
cfg1&= _WDTE_OFF ; WDT disabled
cfg1&= _PWRTE_OFF ; PWRT disabled
cfg1&= _MCLRE_OFF ; MCLR/VPP pin function is digital input
cfg1&= _CP_OFF ; Program memory code protection is disabled
cfg1&= _CPD_OFF ; Data memory code protection is disabled
cfg1&= _BOREN_OFF ; Brown-out Reset disabled
cfg1&= _CLKOUTEN_OFF ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled
cfg1&= _FCMEN_OFF ; Fail-Safe Clock Monitor is disabled
__CONFIG _CONFIG1, cfg1
cfg2 = _WRT_OFF ; Write protection off
cfg2&= _PLLEN_OFF ; 4x PLL disabled
cfg2&= _STVREN_ON ; Stack Overflow or Underflow will cause a Reset
cfg2&= _BORV_19 ; Brown-out Reset Voltage (Vbor), low trip point selected.
cfg2&= _LVP_OFF ; High-voltage on MCLR/VPP must be used for programming
__CONFIG _CONFIG2, cfg2
#ENDCONFIG
#ENDIF
;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF
DEFINE OSC 16
include "modedefs.bas"
ANSELA = %00000000 ' Set PORTA pins to digital I/O
ANSELB = %00000000 ' Set PORTB pins to digital I/O
ANSELC = %00000000 ' Set PORTC pins to digital I/O
WPUB = %00000000 'DISABLE WEAK PULL UP
TRISB=%11110000 'SET PORTB TO OUTPUT
TRISA=%00000000 'SET PORTA TO OUTPUT
TRISC=%00000000 'SET PORTC TO OUTPUT
OSCCON = %01111111 'SET INTOSC TO 16MHZ
' Set LCD Data port
DEFINE LCD_DREG PORTC
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTA
' Set LCD Register Select bit
DEFINE LCD_RSBIT 5
' Set LCD Enable port
DEFINE LCD_EREG PORTA
' Set LCD Enable bit
DEFINE LCD_EBIT 4
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 1500
' Set data delay time in us
DEFINE LCD_DATAUS 44
LCDOUT $FE, $C0, "TEST"
HighTime VAR WORD
LowTime VAR WORD
BitArray VAR WORD [2]
LSB VAR BitArray.lowbyte
MSB VAR BitArray.Highbyte
Signal var PORTB.6
i var word
WaitForStartBit:
GOSUB MeasureLow
IF (LowTime < 9500) OR (LowTime > 10500) THEN WaitForStartBit ' 9.5-10.5ms qualifies
GOSUB MeasureHigh
IF (HighTime < 1500) OR (HighTime > 2500) THEN WaitForStartBit ' 1.5-2.5ms qualifies
NextLevel:
For i = 0 to 31
GOSUB MeasureLow
IF (LowTime > 400) AND (LowTime < 800) THEN BitArray.0[i] = 1 ' 500-700us qualifies as 1
IF (LowTime > 1700) AND (LowTime < 2320) THEN BitArray.0[i] = 0 ' 1800-2200us qualifies as 0
NEXT
LCDOUT $FE,$01, "HighWord", DEC MSB
LCDOUT $FE,$C0, "LowWord", DEC LSB
Pause 1000
Goto WaitForStartBit
MeasureLow:
LowTime = 0
While Signal = 1 : WEND ' Wait for low level
While Signal = 0 ' Measure low level
LowTime = LowTime + 100 ' Resolution is 100us, change if needed
PauseUS 92 ' Tweak to calibrate, depends on actual loop time
WEND
RETURN
MeasureHigh:
HighTime = 0
While Signal = 0 : WEND ' Wait for low
While Signal = 1 ' Measure high level
HighTime = HighTime + 1 ' Resolution is 100us, change if needed
PauseUS 92 ' Tweal to calibrate, depends on actual loop time
WEND
RETURN
Bookmarks