Ok on the initialisation, all sorted out now.
I have managed to compress the access violation to the following code, it is part of a much bigger program and these are the parts that are taken from that in order to demonstrate the problem, the real code is not like this.
The violation occurs if the routine "phone_ok" is un-commented.
Code: Select all
Device=18f67J11
Public Const phone_ok_high(246) As Byte=
(4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
4,198,4,198,4,198,4,198,4,0,4,198,4,198,4,198,
4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,0,
4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,0,
4,198,4,198,4,198,4,198,4,198,4,0,4,198,4,198,
4,198,4,198,4,0,4,198,4,198,4,198,4,198,4,0,
7,0,4,198,4,198,4,198,4,0,7,0,4,198,4,198,
4,198,4,0,7,0,7,0,4,198,4,198,4,0,7,0,
7,0,4,198,4,198,4,0,7,0,7,0,4,198,4,198,
0,7,0,7,0,7,0,4,198,4,0,7,0,7,0,7,
0,4,198,4,0,7,0,7,0,7,0,7,0,4,198,4,
0,7,0,7,0,7,0,4,0,7,0,7,0,4,0,7,
0,4,0,4,0,4)
'******************************************************************************
'******************************************************************************
Public Const phone_ok_low(246) As Byte=
(31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
31,24,31,24,31,24,31,24,31,0,31,24,31,24,31,24,
31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,0,
31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,0,
31,24,31,24,31,24,31,24,31,24,31,0,31,24,31,24,
31,24,31,24,31,0,31,24,31,24,31,24,31,24,31,0,
224,0,31,24,31,24,31,24,31,0,224,0,31,24,31,24,
31,24,31,0,224,0,224,0,31,24,31,24,31,0,224,0,
224,0,31,24,31,24,31,0,224,0,224,0,31,24,31,24,
0,224,0,224,0,224,0,31,24,31,0,224,0,224,0,224,
0,31,24,31,0,224,0,224,0,224,0,224,0,31,24,31,
0,224,0,224,0,224,0,31,0,224,0,224,0,31,0,224,
0,31,0,31,0,31)
'******************************************************************************
'******************************************************************************
Public Const phone_ok_steps(246) As Byte=
(47,4,32,1,32,1,26,3,3,1,28,1,3,1,28,1,
3,1,23,2,3,1,3,1,24,1,3,1,3,1,24,1,
3,1,3,1,20,2,2,1,3,1,3,1,21,1,2,1,
3,1,3,1,18,1,2,1,2,1,3,1,2,1,19,1,
2,1,2,1,2,1,2,1,17,1,2,1,1,1,2,1,
2,1,2,1,4,1,2,1,2,1,2,1,1,1,2,1,
9,1,2,1,4,1,2,1,2,1,2,1,2,1,2,1,
16,1,2,1,3,1,2,1,2,1,2,3,13,1,3,1,
3,1,2,1,4,4,12,1,4,1,3,1,2,2,1,2,
2,2,12,1,4,1,3,1,3,2,4,2,12,1,4,1,
3,1,1,2,3,1,2,2,12,1,4,1,3,2,3,3,
2,2,12,1,4,1,2,2,2,3,4,2,12,1,4,3,
2,2,1,3,1,2,2,12,1,7,2,4,1,1,1,2,
2,12,1,7,2,2,1,1,1,1,1,1,2,13,6,2,
2,2,1,1,1,1,2,23,2,2,1,1,2,25,2,2,
2,27,4,29,2,9)
'******************************************************************************
'******************************************************************************
Dim steps_loop As Word
Dim steps As Word
Dim loop_1 As Word
Dim current_steps As Byte
Dim display_high As Byte
Dim display_low As Byte
{
****************************************************************************
* Name : CReadByte *
* Purpose : Return the data at requested memory address *
****************************************************************************
}
Public Function CReadByte(PAddress As TABLEPTR) As TABLAT
ASM
Clrf EECON1
Bsf EECON1,EEPGD,0
Tblrd*+
End ASM
End Function
Public Sub phone_ok() 'subroutine to call for printing to screen
display_high=0
display_low=0
'READ THE NUMBER OF REPEAT STEPS FROM THE "STEPS" CData TABLE AND
'USE THE LOOP AS INDEX FOR THE LOW AND HIGH BYTE DATA TABLES.
'##################################
For steps_loop = 0 To steps 'number of loop in the steps file
current_steps=CReadByte(@phone_ok_steps+steps_loop) 'read number of steps to use in current screen write
display_high=CReadByte(@phone_ok_high_byte+steps_loop) 'read the high byte value using the steps position
display_low=CReadByte(@phone_ok_low_byte+steps_loop) 'read the low byte value using the steps position
loop_1 = 0 'clear the loop counter
'High (RS) 'select RS for data writing
'Low (CS) 'enable display data port
While loop_1 < current_steps
'DISPLAY = display_high 'load the data on the port
'WR = 0 'initiate WRITE
'WR = 1 'release WRITE line
'DISPLAY = display_low 'load the data on the port
'WR = 0 'initiate WRITE
'WR = 1 'release WRITE line
Inc (loop_1)
Wend
Next
'High (CS) 'disable display data port
'Low (RS) 'idle RS low after this routine
'##################################
End Sub
'IF THIS LINE IS NOT COMMENTED OUT THE ACCESS VIOLATION HAPPENS EACH COMPILE
'phone_ok
The CReadbyte code was sent to me by Tim ages ago but this is the first time I have tried it.
I am sure it is very simple but I am stuck now and do not know what to do.