Dim error

ericgibbs

Joined Jan 29, 2010
18,766
Hi C.
Works OK in this test program.
E
Code:
'18F2431 ASM led test

Define CONFIG1L = 0x00
    Define CONFIG1H = 0x86
        Define CONFIG2L = 0x0c
            Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x81
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

''Define SIMULATION_WAITMS_VALUE = 1  'SIMULATION ONLY

        
Dim fifo(16) As Byte
Dim fifostart As Byte
Dim fifoend As Byte



        OSCCON = %01110001  'internal 8Mhz clock

'I have only changed these to suit a board I am testing,
'dont want To rewire judt To test an LED
TRISA = %10011111
TRISB = %00001111
TRISC = %10001001


main:

    If PORTA.7 = 1 Then
        RA6 = 1  'LED
    Endif

If PORTA.7 = 0 Then
RA6 = 0  'LED
Endif

        Goto main
End
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi C.
Works OK in this test program.
E
Code:
'18F2431 ASM led test

Define CONFIG1L = 0x00
    Define CONFIG1H = 0x86
        Define CONFIG2L = 0x0c
            Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x81
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

''Define SIMULATION_WAITMS_VALUE = 1  'SIMULATION ONLY

     
Dim fifo(16) As Byte
Dim fifostart As Byte
Dim fifoend As Byte



        OSCCON = %01110001  'internal 8Mhz clock

'I have only changed these to suit a board I am testing,
'dont want To rewire judt To test an LED
TRISA = %10011111
TRISB = %00001111
TRISC = %10001001


main:

    If PORTA.7 = 1 Then
        RA6 = 1  'LED
    Endif

If PORTA.7 = 0 Then
RA6 = 0  'LED
Endif

        Goto main
End
Hi E,
Thanks.
Can I post the whole program, to see if it configures at your end?
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi E,
I didn't write this program (much beyond my skills), and it is sent to me as TXT and CODE, the TXT doesn't compile these errors, but the CODE compiles these errors. It is not being written in Oshonsoft, which may be a clue.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi C,
Post the program.
E
Hi E,
Here's CODE and TXT
C


Code:
'18F4431 32MHz XTL REMOTE_SLAVE 164 160223 2330

Define CONFIG1L = 0x00
Define CONFIG1H = 0x06    '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80    'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20


Dim wordTemp As Word
Dim i As Word
dim fifo(16) as byte
dim fifoStart as byte
dim fifoEnd as byte
Dim ccpDone As Bit
Dim previous as Bit
Dim TXbyte as byte
Dim bitCount as byte
dim serialCount as word

OSCCON = %01110000        '& h70
TRISA = %11000000            '7=OSC, 6=OSC,
TRISC = %11111000            '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA 1=serial out
LATC.0 = 0                    'ensure data is low
LATC.2 = 0                    'and clock
LATC.1=1                        'serial idle
For i = 0 To 7
    LATC.2 = 1                'send positive clock edge
    LATC.2 = 0                'send negative edge
Next i
T1CON = %00100000            'prescaler = 4
T1CON.0 = 1                    'start timer
PIE2.CCP2IE = 1            'CCP2 interrupts enable
fifoStart=0
fifoEnd=0
INTCON.PEIE = 1
INTCON.GIE = 1
While 1
    if serialCount>=9600 then        'every second do this
        serialCount=0                    'clear the count
        putFifo("M")                    'send the string as seperate bytes
        putFifo("i")
        putFifo("k")
        putFifo("e")
        putFifo(" ")
        putFifo("W")
        putFifo("a")
        putFifo("s")
        putFifo(" ")
        putFifo("E")
        putFifo("r")
        putFifo("e")
        putFifo("!")
        putFifo("!")
        putFifo(0x0d)
        putFifo(0x0a)
    Endif
Wend
End   

proc putFifo(dat as byte)
    while ((fifoEnd-fifoStart) AND 0x0f)=0x0f
    wend   
    fifo(fifoEnd)=dat                                    'add data to queue
    fifoEnd=(fifoEnd+1) AND 0x0f                    'and increment pointer
End Proc   

function getFifo() as byte                            'note, doesn't test if fifo is empty
    getFifo=fifo(fifoStart)                            'so always call getFifoLen first
    fifoStart=(fifoStart+1) AND 0x0f
End Function                                                                                     

function getFifoLen() as byte
    getFifoLen=(fifoEnd-fifoStart) AND 0x0f
End Function

On High Interrupt            'go via location 0x0008
Save System
    if PIR2.CCP2IF Then
        serialCount=serialCount+1
        wordTemp.LB=CCPR2L                    'ensure next interrupt is
        wordTemp.HB=CCPR2H                    'in 208*2=832 instruction cycles
        wordTemp=wordTemp+208                '208 is 2,000,000/9600 = 104uS or the time for 1 bit at 9600 baud
        CCPR2H=wordTemp.HB                    'it's really important that the high byte gets written first
        CCPR2L=wordTemp.LB                    'write it back
        LATC.1=PORTC.1                            'ensure latch is same as current CCP output
        if ccpDone then
            bitCount=0
            if getFifoLen() then
                TXbyte=getFifo()
                CCP2CON=%1001                    'pin high and low on next interrupt = start bit
                ccpDone=false
                previous=0
            Endif
        else
            'we're sending a byte
            if bitCount<9 then
                if TXbyte.1=previous then
                    'just need the interrupt
                    CCP2CON=%1010
                else
                    'we need to flip the bit
                    if previous Then
                        'we need a zero next
                        previous=0
                        CCP2CON=%1001
                    else
                        'we need a one next
                        previous=1
                        CCP2CON=%1000
                    endif
                endif
                TXbyte=shiftRight(TXbyte,1)
            else
                'doing the stop bits
                if bitCount<10 then
                    if previous then
                        CCP2CON=%1010        'just need interrupt
                    else
                        previous=1
                        CCP2CON=%1000        'go high next interrupt
                    endif
                else
                    ccpDone=true
                Endif
            Endif
        Endif
        bitCount=bitCount+1
        PIR2.CCP2IF=0
    Endif
Resume
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
It appears to accept the Dim's , but the rest of the Code reports endless errors.

It is not compatible with OSH.?

E
 

ericgibbs

Joined Jan 29, 2010
18,766
Hi C,
Arduino is 'brand' of the 'C' language.

The Arduino IDE is a free download and use program, why don't you download it and install.?

There are many features of the Arduino series that you may find useful and easy to use on parts of your project.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi C,
Arduino is 'brand' of the 'C' language.

The Arduino IDE is a free download and use program, why don't you download it and install.?

There are many features of the Arduino series that you may find useful and easy to use on parts of your project.

E
Hi E,
I have Arduino, and have copied and pasted downloaded programs onto them, but have never got into programming them. (For me it's just too difficult)
Thanks.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi E,
I've laundered it! comment all out, copy and paste to a txt file, re-introduce it to OSH, and uncomment.
It compiles down much better.
What do you think?
Code:
'18F4431 32MHz XTL REMOTE_SLAVE 164 110123 1103 test
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06  '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80  'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20


Dim wordTemp As Word
Dim i As Word
Dim fifo(16) As Byte
Dim fifostart As Byte
Dim fifoend As Byte
Dim ccpDone As Bit
Dim previous As Bit
Dim txbyte As Byte
Dim bitcount As Byte
Dim serialcount As Word

OSCCON = %01110000  '& h70
TRISA = %11000000  '7=OSC, 6=OSC,
TRISC = %11111000  '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA 1=serial out
LATC.0 = 0  'ensure data is low
LATC.2 = 0  'and clock
LATC.1 = 1  'serial idle
For i = 0 To 7
    LATC.2 = 1  'send positive clock edge
    LATC.2 = 0  'send negative edge
Next i
T1CON = %00100000  'prescaler = 4
T1CON.0 = 1  'start timer
PIE2.CCP2IE = 1  'CCP2 interrupts enable
fifostart = 0
fifoend = 0
INTCON.PEIE = 1
INTCON.GIE = 1
While 1
    If serialcount >= 9600 Then  'every second do this
serialcount = 0  'clear the count
'putfifo("M")  'send the string as seperate bytes
'putfifo("i")
'putfifo("k")
'putfifo("e")
'putfifo(" ")
'putfifo("W")
'putfifo("a")
'putfifo("s")
'putfifo(" ")
'putfifo("E")
'putfifo("r")
'putfifo("e")
'putfifo("!")
'putfifo("!")
'putfifo(0x0d)
'putfifo(0x0a)
Endif
Wend
End                                               

Proc putfifo(dat As Byte)
While ((fifoend - fifostart) And 0x0f) = 0x0f
Wend
fifo(fifoend) = dat  'add data to queue
fifoend = (fifoend + 1) And 0x0f  'and increment pointer
End Proc                                         

Function getFifo() As Byte  'note, doesn't test if fifo is empty
getFifo = fifo(fifostart)  'so always call getFifoLen first
fifostart = (fifostart + 1) And 0x0f
End Function                                     

Function getfifolen() As Byte
getfifolen = (fifoend - fifostart) And 0x0f
End Function                                     

On High Interrupt  'go via location 0x0008
Save System
If PIR2.CCP2IF Then
serialcount = serialcount + 1
wordTemp.LB = CCPR2L  'ensure next interrupt is
wordTemp.HB = CCPR2H  'in 208*2=832 instruction cycles
wordTemp = wordTemp + 208  '208 is 2,000,000/9600 = 104uS or the time for 1 bit at 9600 baud
CCPR2H = wordTemp.HB  'it's really important that the high byte gets written first
CCPR2L = wordTemp.LB  'write it back
LATC.1 = PORTC.1  'ensure latch is same as current CCP output
If ccpDone Then
bitcount = 0
If getfifolen() Then
txbyte = getFifo()
CCP2CON = %1001  'pin high and low on next interrupt = start bit
ccpDone = False
previous = 0
Endif
Else
'we're sending a byte
If bitcount < 9 Then
If txbyte.1 = previous Then
'just need the interrupt
CCP2CON = %1010
Else
'we need to flip the bit
If previous Then
'we need a zero next
previous = 0
CCP2CON = %1001
Else
'we need a one next
previous = 1
CCP2CON = %1000
Endif
Endif
txbyte = ShiftRight(txbyte, 1)
Else
'doing the stop bits
If bitcount < 10 Then
If previous Then
CCP2CON = %1010  'just need interrupt
Else
previous = 1
CCP2CON = %1000  'go high next interrupt
Endif
Else
ccpDone = True
Endif
Endif
Endif
bitcount = bitcount + 1
PIR2.CCP2IF = 0
Endif
Resume
C
 

sagor

Joined Mar 10, 2019
903
Hi,
Does anyone know whatis causing this error, please?
Camerart
Looking at the error, the text may not have real < cr> or <lf> characters but some type of Linux or multilingual characters. I suspect you just copy/paste the original code. Hence the compiler sees three lines as one statement, which it cannot compile.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
This CODE is now compiling in Osh, but not working, and shows this error.
C
Code:
'18F4431 32MHz XTL REMOTE_SLAVE UART_GPS 120123 0900 test

Define CONFIG1L = 0x00
Define CONFIG1H = 0x06  '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80  'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20

Define SIMULATION_WAITMS_VALUE = 1  'Comment in for SIM out for PIC

TRISC = %00000000  '1=GPS

Dim wordTemp As Word
Dim i As Word
Dim fifo(16) As Byte
Dim fifoStart As Byte
Dim fifoEnd As Byte
Dim ccpDone As Bit
Dim previous As Bit
Dim TXbyte As Byte
Dim bitCount As Byte
Dim serialCount As Word
Dim length As Byte

OSCCON = %01110000  '& h70
TRISA = %11000000  '7=OSC, 6=OSC,
TRISC = %11111000  '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA 1=serial out
LATC.1 = 1  'serial idle
T1CON = %00100000  'prescaler = 4
T1CON.0 = 1  'start timer
CCP2CON = %1010  'interrupt only
PIE2.CCP2IE = 1  'CCP2 interrupts enable
fifoStart = 0
fifoEnd = 0
INTCON.PEIE = 1
INTCON.GIE = 1
serialCount = 0
Call putFifo(0xff)  'send a dummy byte to get in sync
While 1
If serialCount >= 9600 Then  'do this every second
serialCount = 0  'clear the count

Call putFifo(77)

Call putFifo(105)
Call putFifo(107)
Call putFifo(101)
Call putFifo(32)
Call putFifo(87)
Call putFifo(97)
Call putFifo(115)
Call putFifo(32)
Call putFifo(69)
Call putFifo(114)
Call putFifo(101)
Call putFifo(33)
Call putFifo(33)
Call putFifo(13)
Call putFifo(10)
Endif
Wend
End                                               

Proc putFifo(dat As Byte)
While ((fifoEnd - fifoStart) And 0x0f) = 0x0f
Wend
fifo(fifoEnd) = dat  'add data to queue
fifoEnd = (fifoEnd + 1) And 0x0f  'and increment pointer
End Proc                                         

Function getFifo() As Byte  'note, doesn't test if fifo is empty
getFifo = fifo(fifoStart)  'so always call getFifoLen first
fifoStart = (fifoStart + 1) And 0x0f
End Function                                     

Function getFifoLen() As Byte
getFifoLen = (fifoEnd - fifoStart) And 0x0f
End Function                                     

On High Interrupt  'go via location 0x0008
Save System
If PIR2.CCP2IF Then
serialCount = serialCount + 1
wordTemp.LB = CCPR2L  'ensure next interrupt is
wordTemp.HB = CCPR2H  'in 208*4=832 instruction cycles
wordTemp = wordTemp + 208  '208 is 2,000,000/9600 = 104uS or the time for 1 bit at 9600 baud
CCPR2H = wordTemp.HB  'it's really important that the high byte gets written first
CCPR2L = wordTemp.LB  'write it back
LATC.1 = PORTC.1  'ensure latch is same as current CCP output
If ccpDone Then
bitCount = 0
length = getFifoLen()
If length > 0 Then
TXbyte = getFifo()
CCP2CON = %1001  'pin high and low on next interrupt = start bit
ccpDone = False
previous = 0
Endif
Else
'we're sending a byte
If bitCount < 9 Then
If TXbyte.1 = previous Then
'just need the interrupt
CCP2CON = %1010
Else
'we need to flip the bit
If previous Then
'we need a zero next
previous = 0
CCP2CON = %1001
Else
'we need a one next
previous = 1
CCP2CON = %1000
Endif
Endif
TXbyte = ShiftRight(TXbyte, 1)
Else
'doing the stop bits
If bitCount < 10 Then
If previous Then
CCP2CON = %1010  'just need interrupt
Else
previous = 1
CCP2CON = %1000  'go high next interrupt
Endif
Else
ccpDone = True  'stop bits will still be generated - this happens at bitCount=10
Endif  'and output will stay high until next byte
Endif
Endif
bitCount = bitCount + 1
PIR2.CCP2IF = 0
Endif
Resume
 

Attachments

sagor

Joined Mar 10, 2019
903
Eric, "While 1" compiles ok in PIC18 Simulator IDE V4.38 (my own test program)
Osh creates a temporary bit storage location when one views the ASM code generated (snippet below):

Code:
; 7: While 1
L0002:
;       oshonsoft_temp_bit1 EQU 0x00F,0
    BSF 0x00F,0
    BTFSS 0x00F,0
    BRA L0003
; 8:
; 9: For i = 0 To 7
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi S,
I have 4.34.
What does your ASM show?
If it could be programmed in a different way to get the same results, what would that look like?
C
 
Last edited:
Top