Dim error

Ya’akov

Joined Jan 27, 2019
9,170
Hi E,
Mine doesn't show that error, but something is odd around that section.
Thanks.
C
I have only been lightly following this thread but a previous problem appeared to involve line endings. The editor makes the difference invisible but the compiler chokes on it. If you look that the source in a hex editor or a code editor that can show line endings, is there anything odd in that section?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
I have only been lightly following this thread but a previous problem appeared to involve line endings. The editor makes the difference invisible but the compiler chokes on it. If you look that the source in a hex editor or a code editor that can show line endings, is there anything odd in that section?
Hi Y,
We had a problem previously with TABS, whre instead SPACES were used, and messed things up, so this is a difficult area.
I've never been able to follow ASM and LST editors, although I can see what you mean.
I'll have a look and see if I can spot anything.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi C,
Now installed Version 4.42, your test program compiles OK.
'18F4431 32MHz XTL REMOTE_SLAVE UART_GPS 120123 0900 test
E
Hi E,
Good.
Have you any idea why the update allowed it to compile? It's a bit too subtle really.
Does this tell you that the CODE should be written in a better way, or is it simply an OSH problem?
C
 

ericgibbs

Joined Jan 29, 2010
18,865
Hi C,
Vlad is constantly added to and improving his compiler.
The only way to know which features he has added is to re-read the latest manual.

I don't know what you mean by 'written in a better way'?

If you cannot compile your test program, get version 4.42

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi C,
Vlad is constantly added to and improving his compiler.
The only way to know which features he has added is to re-read the latest manual.

I don't know what you mean by 'written in a better way'?

If you cannot compile your test program, get version 4.42

E
Hi E,
I have 4.42 and can compile it.
In the SIM, it runs, then gets [TX Line Statur Incorrect stop bit!! ]
C
 

ericgibbs

Joined Jan 29, 2010
18,865
Hi C,
As an example, from the latest manual for the While command.
Clip:
While statement will accept all possible complex expressions that evaluate to Bit data type. The same is valid for If-Then statement. Case statement can also contain complex expressions.
For statement will accept all possible complex expressions for the initial expression, for the To argument, and for the optional Step argument as well.

In the SIM, it runs, then gets [TX Line Statur Incorrect stop bit!! ]

Does this error show immediately the program is run in the sim.?

E
 

ericgibbs

Joined Jan 29, 2010
18,865
Hi C,
I need to know what action you have taken in order to get your error message.??

I see an error msg 'serial port not enabled'
Are we using the same program.?
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi C,
As an example, from the latest manual for the While command.
Clip:
While statement will accept all possible complex expressions that evaluate to Bit data type. The same is valid for If-Then statement. Case statement can also contain complex expressions.
For statement will accept all possible complex expressions for the initial expression, for the To argument, and for the optional Step argument as well.

In the SIM, it runs, then gets [TX Line Statur Incorrect stop bit!! ]

Does this error show immediately the program is run in the sim.?

E
Hi E,
It starts, and RC1 comes on, then app 35000us the 'stop bit' error shows, but doesn't stall.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi C,
As an example, from the latest manual for the While command.
Clip:
While statement will accept all possible complex expressions that evaluate to Bit data type. The same is valid for If-Then statement. Case statement can also contain complex expressions.
For statement will accept all possible complex expressions for the initial expression, for the To argument, and for the optional Step argument as well.

In the SIM, it runs, then gets [TX Line Statur Incorrect stop bit!! ]

Does this error show immediately the program is run in the sim.?

E
Hi E,
It starts, and RC1 comes on, then app 35000us the 'stop bit' error shows, but doesn't stall.
C

Hi C,
I need to know what action you have taken in order to get your error message.??

I see an error msg 'serial port not enabled'
Are we using the same program.?
E
Hi E,
Yes, I'm using
18F4431 32MHz XTL REMOTE_SLAVE UART_GPS 120123 0900 test

I just compile load, and with the Microcontroller view, Watch variables, and Software UART, get these results.
C
 

ericgibbs

Joined Jan 29, 2010
18,865
Hi,
Post me the latest copy of that program, name it, say ' Debug1' just to make sure I have the same complete code as you.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
Post me the latest copy of that program, name it, say ' Debug1' just to make sure I have the same complete code as you.
E
Code:
'DEBUG 1
'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
Hi E,
Same resutl!
C
 

ericgibbs

Joined Jan 29, 2010
18,865
hi,
Sorry, but your post doesn't help me, what do you mean.?

I need to see the program you are using on that test, else I cannot help you.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi,
Sorry, but your post doesn't help me, what do you mean.?

I need to see the program you are using on that test, else I cannot help you.

E
Hi E,
Perhaps a mix up.

Anyway! If we can start here again.
Here's a program that compiles, and gives the same result in SIM: Rc1 on for a while, then after a while the 'stop bit' error occures.

Is this program ok?
C
Code:
'DEBUG 2

'18F4431 32MHz XTL REMOTE_SLAVE UART_GPS 110123 2301 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
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
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,865
Hi C.
The problem is located here, using the Run command until the break command, then Single Step shows the error.
E

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

Break '''''''''''''''''''''''''''''''''''' break point

PORTC.1 = 1 '''''' error msg
LATC.1 = PORTC.1 'ensure latch is same as current CCP output

If ccpDone Then
 
Last edited:
Top