PDA

View Full Version : error worring pbp247



chai98a
- 16th January 2010, 03:09
Found this :code crosses boundary @800
what is problem of my code


DEFINE LOADER_USED 1

INCLUDE "modedefs.bas"

'-------------------------- Ports settings ---------------------------------

TRISA = %00000001
PORTA = %00000001
TRISB = %00000111
PORTB = %00000111
'-------------------------- Special function registers -------------------
'-------------------------- Variables ---------------------------
'*****74HC595 DE???KENLER?N? TANIMLA*****
DTA var PORTB.5 '21--14 b7
Latch var PORTB.6 '22--12 b6
CLK var PORTB.7 '23--11 b5
Digit_1 var PORTB.4
Digit_2 var PORTB.0

IN_1 var PORTA.3
IN_2 var PORTA.1
IN_3 var PORTA.2
IN_4 var PORTA.4
sw_mode var PORTA.0
sw_up var PORTB.1
sw_down var PORTB.2
sw_Mode_data VAR Byte
sw_up_data var Byte
sw_down_data VAR Byte
Data_mode VAR Byte

I VAR Byte
M VAR Byte ' delay for motro step
N VAR Byte
P VAR Byte
T1 VAR Word
loaddata VAR Word


Dataorg VAR Byte ' keep data position
Dataorg_ADDRESS con 0
DATA_MOTOR VAR Byte
DATA_MOTORx VAR Byte
DATA_MOTOR_ADDRESS con 2
VALUE VAR Byte
DATA_save_ADDRESS con 4
DATA_power_ADDRESS con 6

'-------------------------- Main program -------------------------
pause 200
M = 10 ' delay for motro step
N = 0 ' data motor conter
P = 0
' Write Dataorg_ADDRESS , 13
' 'EWRITE DATA_MOTOR_ADDRESS , [100]
' Write DATA_save_ADDRESS , 2
' Write DATA_power_ADDRESS , 15

Read DATA_MOTOR_ADDRESS,DATA_MOTOR

MainProgram:

If sw_mode = 0 Then
GoTo sw_m
EndIf
CHK_sw:

GoSub Show_7seg

If sw_up = 0 Then
pause 150
GoTo T_Right 'up OPEN
PORTA = %00000001
Else
If sw_down = 0 Then
pause 150
GoSub T_left
PORTA = %00000001
EndIf
EndIf

GoTo MainProgram ' Return to main program
'++++++++++++++++++++++ mode ++++++++
Mode_option:
T1 = 2300
loopa:
If T1 = 0 Then GoTo Select_A
T1 = t1-1

If sw_mode = 0 Then
sw_m:
sw_Mode_data = sw_Mode_data+10
pause 200 ' delay 3 sec
T1=2300 'T1 ******
VALUE = sw_Mode_data
GoSub Show_7segx
EndIf
If sw_up_data <> 2 Then
If sw_up = 0 Then
pause 150
sw_up_data = 2
T1=2300 'T1 ******
Data_mode = sw_Mode_data + sw_up_data
VALUE = Data_mode
GoSub Show_7segx
EndIf
EndIf
If sw_down_data <> 1 Then
If sw_down = 0 Then
pause 150
sw_down_data = 1
T1=2300 'T1******
Data_mode = sw_Mode_data + sw_down_data
VALUE = Data_mode
GoSub Show_7segx
EndIf
EndIf
Data_mode = sw_Mode_data + sw_up_data + sw_down_data
VALUE = Data_mode
If Data_mode >= 40 Then
pause 150
Data_mode =0
VALUE = DATA_MOTOR
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
GoTo CHK_sw
EndIf
GoSub Show_7segx
'DELAYMS 10
GoTo loopa


Select_A:
Select case Data_mode ' mode 10 preset

Case 11 'Read save data
If sw_up = 0 Then
sw_Mode_data=0
sw_up_data = 0
Read DATA_save_ADDRESS,DATA_MOTORx
'EWrite 15 , [ DATA_MOTORx ]
If DATA_MOTOR > DATA_MOTORx Then
'n = 13 - 2 = 11
P = DATA_MOTOR - DATA_MOTORx
'Write 16 , P
GoSub MOVE_down 'load data
EndIf
Else
sw_Mode_data=0
sw_up_data = 0
EndIf

Case 12 'Read power data
If sw_down =0 Then
sw_Mode_data=0
sw_down_data = 0
Read DATA_power_ADDRESS, DATA_MOTORx
If DATA_MOTORx < DATA_MOTOR Then
'n = 50 - 8 = 48
P = DATA_MOTORx - DATA_MOTOR
'N=30
GoSub MOVE_up 'load data
EndIf
Else
sw_Mode_data=0
sw_down_data = 0
EndIf


Case 21
If sw_up =0 Then
sw_Mode_data=0
sw_up_data = 0
DATA_MOTOR = DATA_MOTOR +1
Write DATA_save_ADDRESS , DATA_MOTOR
Else
sw_Mode_data=0
sw_up_data = 0
EndIf

Case 22
If sw_down = 0 Then
sw_Mode_data=0
sw_down_data = 0
DATA_MOTOR = DATA_MOTOR +1
Write DATA_power_ADDRESS , DATA_MOTOR
Else
sw_Mode_data=0
sw_down_data = 0
EndIf
Case 23
If sw_up = 0 And sw_down = 0 Then
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
DATA_MOTOR = DATA_MOTOR +1
Write Dataorg_ADDRESS , DATA_MOTOR
Else
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
EndIf

Case 33
If sw_up = 0 And sw_down = 0 Then
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
GoSub Reset_motor
Else
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
EndIf
Case else
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
End Select
GoSub Show_7seg

sw_up_data = 0
sw_down_data = 0
GoTo CHK_sw

'-------------------------- User subroutine_1--------------------------

Show_7seg:
VALUE = DATA_MOTOR

Show_7segx:
For I = 0 To 1 ' Loop through 4 digits
N = VALUE Dig I ' Get digit to display
GoSub Display1 ' Display the digit
If sw_Mode_data > 1 Then
loaddata = loaddata | %10000000 ' led on setup
EndIf
If I = 0 Then

SHIFTOUT DTA,CLK,1,[loaddata\8]
High Latch
Low Digit_1
High Digit_2
Low Latch
Else

SHIFTOUT DTA,CLK,1,[loaddata\8]
High Latch
High Digit_1
Low Digit_2
Low Latch

EndIf

Next ' Do next digit

Return ' Return from subroutine



Display1: ' looup data for 7 seg
LookUp N, [$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],loaddata
Return
''-------------------------- User subroutine_2--------------------------

T_Right: ' 3 1 2 4 'up OPEN

PORTA =%00001011 '2
pause M
PORTA =%00000111 '4
pause M
PORTA =%00010101 '6
pause M
PORTA =%00011001 '8
pause M

DATA_MOTOR = DATA_MOTOR+1
If DATA_MOTOR >= 60 Then
DATA_MOTOR = 60

Else
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
EndIf
Toggle Digit_2
Toggle Digit_1
Return

'---------------------
T_left: 'down CLOSE

PORTA =%00011001 '8
pause M
PORTA =%00010101 '6
pause M
PORTA =%00000111 '4
pause M
PORTA =%00001011 '2
pause M

DATA_MOTOR = DATA_MOTOR - 1
If DATA_MOTOR <= 0 Then
DATA_MOTOR = 0
'EWRITE DATA_MOTOR_ADDRESS , [ DATA_MOTOR ]
Else
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
EndIf
Toggle Digit_2
Toggle Digit_1
Return

'=============================
'Original position
Reset_motor: ' move down
N = N + 1

PORTA =%00011001 '8
pause M
PORTA =%00010101 '6
pause M
PORTA =%00000111 '4
pause M
PORTA =%00001011 '2
pause M

If N < 65 Then
Toggle Digit_1
GoTo Reset_motor
EndIf
'=======================
'Variable = EREAD Address
Read Dataorg_ADDRESS , n
DATA_MOTOR = 0 'KEEP DATA FOR SHOW DISPLAY
'=======================
MOVE1:

PORTA =%00001011 '2
pause M
PORTA =%00000111 '4
pause M
PORTA =%00010101 '6
pause M
PORTA =%00011001 '8
pause M

If N <> 0 Then
N = N - 1
Toggle Digit_1
DATA_MOTOR = DATA_MOTOR + 1
GoTo MOVE1
EndIf
PORTA = %00000001
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
'return
GoTo CHK_sw

'=====================================
MOVE_down: 'per-set save

PORTA =%00011001 '8
pause M
PORTA =%00010101 '6
pause M
PORTA =%00000111 '4
pause M
PORTA =%00001011 '2
pause M

If P > 0 Then
P = P - 1
Toggle Digit_1
DATA_MOTOR = DATA_MOTOR - 1
GoSub Show_7seg
GoTo MOVE_down
EndIf
PORTA = %00000001
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
Return

'===================================
MOVE_up: 'per-set power

PORTA =%00001011 '2
pause M
PORTA =%00000111 '4
pause M
PORTA =%00010101 '6
pause M
PORTA =%00011001 '8
pause M

If P > 0 Then
P = P - 1
Toggle Digit_1
DATA_MOTOR = DATA_MOTOR + 1
GoTo MOVE_up
EndIf
PORTA = %00000001
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
Return


end

Archangel
- 16th January 2010, 04:44
I think you will find the answer here: http://www.picbasic.co.uk/forum/showthread.php?t=555
or in the manual sec. 2.5.3

chai98a
- 16th January 2010, 12:22
thank you
after i restart pc and not problem !!!

chai98a
- 17th January 2010, 04:51
pls help me verify my code not work, why???

case 11 and 12 , we cannot read data frome eeprom

case 21 , we cannot write data frome eeprom
case 22 , we cannot write data frome eeprom
case 23 , work fine no problem

I very confuse why case 21 and case22 don't work but case 23 work , code same



Found this :code crosses boundary @800
what is problem of my code


DEFINE LOADER_USED 1

INCLUDE "modedefs.bas"

'-------------------------- Ports settings ---------------------------------

TRISA = %00000001
PORTA = %00000001
TRISB = %00000111
PORTB = %00000111
'-------------------------- Special function registers -------------------
'-------------------------- Variables ---------------------------
'*****74HC595 DE???KENLER?N? TANIMLA*****
DTA var PORTB.5 '21--14 b7
Latch var PORTB.6 '22--12 b6
CLK var PORTB.7 '23--11 b5
Digit_1 var PORTB.4
Digit_2 var PORTB.0

IN_1 var PORTA.3
IN_2 var PORTA.1
IN_3 var PORTA.2
IN_4 var PORTA.4
sw_mode var PORTA.0
sw_up var PORTB.1
sw_down var PORTB.2
sw_Mode_data VAR Byte
sw_up_data var Byte
sw_down_data VAR Byte
Data_mode VAR Byte

I VAR Byte
M VAR Byte ' delay for motro step
N VAR Byte
P VAR Byte
T1 VAR Word
loaddata VAR Word


Dataorg VAR Byte ' keep data position
Dataorg_ADDRESS con 0
DATA_MOTOR VAR Byte
DATA_MOTORx VAR Byte
DATA_MOTOR_ADDRESS con 2
VALUE VAR Byte
DATA_save_ADDRESS con 4
DATA_power_ADDRESS con 6

'-------------------------- Main program -------------------------
pause 200
M = 10 ' delay for motro step
N = 0 ' data motor conter
P = 0
' Write Dataorg_ADDRESS , 13
' 'EWRITE DATA_MOTOR_ADDRESS , [100]
' Write DATA_save_ADDRESS , 2
' Write DATA_power_ADDRESS , 15

Read DATA_MOTOR_ADDRESS,DATA_MOTOR

MainProgram:

If sw_mode = 0 Then
GoTo sw_m
EndIf
CHK_sw:

GoSub Show_7seg

If sw_up = 0 Then
pause 150
GoTo T_Right 'up OPEN
PORTA = %00000001
Else
If sw_down = 0 Then
pause 150
GoSub T_left
PORTA = %00000001
EndIf
EndIf

GoTo MainProgram ' Return to main program
'++++++++++++++++++++++ mode ++++++++
Mode_option:
T1 = 2300
loopa:
If T1 = 0 Then GoTo Select_A
T1 = t1-1

If sw_mode = 0 Then
sw_m:
sw_Mode_data = sw_Mode_data+10
pause 200 ' delay 3 sec
T1=2300 'T1 ******
VALUE = sw_Mode_data
GoSub Show_7segx
EndIf
If sw_up_data <> 2 Then
If sw_up = 0 Then
pause 150
sw_up_data = 2
T1=2300 'T1 ******
Data_mode = sw_Mode_data + sw_up_data
VALUE = Data_mode
GoSub Show_7segx
EndIf
EndIf
If sw_down_data <> 1 Then
If sw_down = 0 Then
pause 150
sw_down_data = 1
T1=2300 'T1******
Data_mode = sw_Mode_data + sw_down_data
VALUE = Data_mode
GoSub Show_7segx
EndIf
EndIf
Data_mode = sw_Mode_data + sw_up_data + sw_down_data
VALUE = Data_mode
If Data_mode >= 40 Then
pause 150
Data_mode =0
VALUE = DATA_MOTOR
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
GoTo CHK_sw
EndIf
GoSub Show_7segx
'DELAYMS 10
GoTo loopa


Select_A:
Select case Data_mode ' mode 10 preset

Case 11 'Read save data
If sw_up = 0 Then
sw_Mode_data=0
sw_up_data = 0
Read DATA_save_ADDRESS,DATA_MOTORx
'EWrite 15 , [ DATA_MOTORx ]
If DATA_MOTOR > DATA_MOTORx Then
'n = 13 - 2 = 11
P = DATA_MOTOR - DATA_MOTORx
'Write 16 , P
GoSub MOVE_down 'load data
EndIf
Else
sw_Mode_data=0
sw_up_data = 0
EndIf

Case 12 'Read power data
If sw_down =0 Then
sw_Mode_data=0
sw_down_data = 0
Read DATA_power_ADDRESS, DATA_MOTORx
If DATA_MOTORx < DATA_MOTOR Then
'n = 50 - 8 = 48
P = DATA_MOTORx - DATA_MOTOR
'N=30
GoSub MOVE_up 'load data
EndIf
Else
sw_Mode_data=0
sw_down_data = 0
EndIf


Case 21
If sw_up =0 Then
sw_Mode_data=0
sw_up_data = 0
DATA_MOTOR = DATA_MOTOR +1
Write DATA_save_ADDRESS , DATA_MOTOR
Else
sw_Mode_data=0
sw_up_data = 0
EndIf

Case 22
If sw_down = 0 Then
sw_Mode_data=0
sw_down_data = 0
DATA_MOTOR = DATA_MOTOR +1
Write DATA_power_ADDRESS , DATA_MOTOR
Else
sw_Mode_data=0
sw_down_data = 0
EndIf
Case 23
If sw_up = 0 And sw_down = 0 Then
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
DATA_MOTOR = DATA_MOTOR +1
Write Dataorg_ADDRESS , DATA_MOTOR
Else
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
EndIf

Case 33
If sw_up = 0 And sw_down = 0 Then
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
GoSub Reset_motor
Else
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
EndIf
Case else
sw_Mode_data=0
sw_up_data = 0
sw_down_data = 0
End Select
GoSub Show_7seg

sw_up_data = 0
sw_down_data = 0
GoTo CHK_sw

'-------------------------- User subroutine_1--------------------------

Show_7seg:
VALUE = DATA_MOTOR

Show_7segx:
For I = 0 To 1 ' Loop through 4 digits
N = VALUE Dig I ' Get digit to display
GoSub Display1 ' Display the digit
If sw_Mode_data > 1 Then
loaddata = loaddata | %10000000 ' led on setup
EndIf
If I = 0 Then

SHIFTOUT DTA,CLK,1,[loaddata\8]
High Latch
Low Digit_1
High Digit_2
Low Latch
Else

SHIFTOUT DTA,CLK,1,[loaddata\8]
High Latch
High Digit_1
Low Digit_2
Low Latch

EndIf

Next ' Do next digit

Return ' Return from subroutine



Display1: ' looup data for 7 seg
LookUp N, [$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],loaddata
Return
''-------------------------- User subroutine_2--------------------------

T_Right: ' 3 1 2 4 'up OPEN

PORTA =%00001011 '2
pause M
PORTA =%00000111 '4
pause M
PORTA =%00010101 '6
pause M
PORTA =%00011001 '8
pause M

DATA_MOTOR = DATA_MOTOR+1
If DATA_MOTOR >= 60 Then
DATA_MOTOR = 60

Else
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
EndIf
Toggle Digit_2
Toggle Digit_1
Return

'---------------------
T_left: 'down CLOSE

PORTA =%00011001 '8
pause M
PORTA =%00010101 '6
pause M
PORTA =%00000111 '4
pause M
PORTA =%00001011 '2
pause M

DATA_MOTOR = DATA_MOTOR - 1
If DATA_MOTOR <= 0 Then
DATA_MOTOR = 0
'EWRITE DATA_MOTOR_ADDRESS , [ DATA_MOTOR ]
Else
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
EndIf
Toggle Digit_2
Toggle Digit_1
Return

'=============================
'Original position
Reset_motor: ' move down
N = N + 1

PORTA =%00011001 '8
pause M
PORTA =%00010101 '6
pause M
PORTA =%00000111 '4
pause M
PORTA =%00001011 '2
pause M

If N < 65 Then
Toggle Digit_1
GoTo Reset_motor
EndIf
'=======================
'Variable = EREAD Address
Read Dataorg_ADDRESS , n
DATA_MOTOR = 0 'KEEP DATA FOR SHOW DISPLAY
'=======================
MOVE1:

PORTA =%00001011 '2
pause M
PORTA =%00000111 '4
pause M
PORTA =%00010101 '6
pause M
PORTA =%00011001 '8
pause M

If N <> 0 Then
N = N - 1
Toggle Digit_1
DATA_MOTOR = DATA_MOTOR + 1
GoTo MOVE1
EndIf
PORTA = %00000001
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
'return
GoTo CHK_sw

'=====================================
MOVE_down: 'per-set save

PORTA =%00011001 '8
pause M
PORTA =%00010101 '6
pause M
PORTA =%00000111 '4
pause M
PORTA =%00001011 '2
pause M

If P > 0 Then
P = P - 1
Toggle Digit_1
DATA_MOTOR = DATA_MOTOR - 1
GoSub Show_7seg
GoTo MOVE_down
EndIf
PORTA = %00000001
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
Return

'===================================
MOVE_up: 'per-set power

PORTA =%00001011 '2
pause M
PORTA =%00000111 '4
pause M
PORTA =%00010101 '6
pause M
PORTA =%00011001 '8
pause M

If P > 0 Then
P = P - 1
Toggle Digit_1
DATA_MOTOR = DATA_MOTOR + 1
GoTo MOVE_up
EndIf
PORTA = %00000001
Write DATA_MOTOR_ADDRESS , DATA_MOTOR
Return


end