PDA

View Full Version : Proton ERead & EWrite problem when using CData, remmber this



Alee
1st February 2012, 14:15
in one of my projects (Egg incubator) i had a big problem when i reset micro or the power removed data in eeprom will erased, after too many trouble i understood when i use CData table Proton IDE don't change EECON1.7 Register so this problem occoured.
Please Remmber when u want use EEPROM set EECON1.7 (EECON1.7 = 1) and when u want use CData clear EECON1.7 (EECON1.7 = 1).

Here is my project (Egg incubator) with Proton IDE & 876A for free

Include "init2_backup.bas"
Cls
Clear
EECON1.7 = 0
T1CON = %00110000 : INTCON = %01000000 : PIE1 = %00000001
PIR1.0 = 0 : TMR1H = $0B : TMR1L = $DC : T1CON.0 = 0
OPTION_REG.7 = 0
On Interrupt GoTo G_S_Int
DelayMS 100
'************************************************* *******************

Af_Stop:
Ele_RH = 0 : Ele_T = 0 : Fan = 0 : Motor = 0

EE_Lock = ERead 100
DelayMS 20
If EE_Lock = 124 Then
L_Title = ERead 101
DelayMS 10
T_3H = ERead 103
DelayMS 10
Motor_Bad = ERead 105
DelayMS 10
D1 = ERead 104
DelayMS 10
If Motor_Bad = 14 Then Motor = 1
T1CON.0 = 1 : INTCON.7 = 1
Else
GoSub Get_TRH
GoTo Be_Sel
EndIf

Lock = 1
Menu = 1
L_TitleT = L_Title
GoSub Get_Value
GoSub Get_Fix
GoSub Get_TRH
GoSub D_Show
Temp = 0
GoTo Main

Be_Sel:
Print At 2,1, $5E, "Select "
Print At 2,14, "OK", $7E
Print At 1,4, " "
DelayMS 50
EECON1.7 = 0
Print At 1, 1, CStr L_TitleT + 5000, $7F, " "

Sel:
If Out_S = 1 Then Out_sel
If K_Sel = 0 Then
DelayMS 80
L_TitleT = L_TitleT + 14
If L_TitleT = 126 Then L_TitleT = 14
EECON1.7 = 0
For State = 0 To 10
LChar = CRead (L_TitleT + 5000 + State)
If LChar = 0 Then Ex_ef
Print At 1, State + 1, LChar, $7F, " "
'Print At 1, 1, CStr L_TitleT + 5000, $7F, " "
DelayMS 100
Next
Wend
Ex_ef:
State = 0
LChar = 0

Pushed:
If K_Sel = 0 Then
If Motor_Bad = 14 Then GoSub Motor_Stop
Inc K_Hold
If K_Hold >= 60 Then
While K_Sel = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 20
Wend
Out_sel:
DelayMS 50
Menu = 0
K_Hold = 0
Menu = 1
L_TitleT = L_Title
Refresh = 1
GoTo Main
EndIf
DelayMS 10
GoTo Pushed
EndIf
K_Hold = 0
EndIf

If Motor_Bad = 14 Then GoSub Motor_Stop

If K_OK = 0 Then
While K_Sel = 0 Or K_OK = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 50
Wend
DelayMS 50
GoTo Af_Sel
EndIf

GoTo Sel

Af_Sel:
Cls
If L_TitleT = 0 Then
Print At 1,1, "<Please Select>"
L_TitleT = 14
DelayMS 500
GoTo Be_Sel
EndIf
EECON1.7 = 0
Print At 1,1, CStr L_TitleT + 5000 , " OK ? "
Print At 2,1, $7F, "Select"
Print At 2,14, "OK", $7E

DelayMS 50

Af_Sel1:
If Motor_Bad = 14 Then GoSub Motor_Stop

If K_Sel = 0 Then GoTo Be_Sel
If K_OK = 0 Then
While K_OK = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 20
Wend
DelayMS 50
If L_Title <> L_TitleT Then
EECON1.7 = 1
L_Title = L_TitleT
T_OV = 0
T_H = 0
T_3H = 0
D1 = 0
EWrite 100, [124]
DelayMS 30
EWrite 101, [L_Title]
DelayMS 40
EWrite 103, [T_3H]
DelayMS 30
EWrite 104, [D1]
DelayMS 30
EndIf
GoSub effect
Refresh = 1
Lock = 1
Menu = 1
T1CON.0 = 1 : INTCON.7 = 1
GoSub Get_TRH
GoSub Get_Value
GoSub Get_Fix
GoTo Main
EndIf

GoTo Af_Sel1

'&&&&&&&&&&&&&&&&&& Main of program


Main:
If Finish = 1 And K_OK = 0 Then
T1CON.0 = 0 : INTCON.7 = 0
GoSub effect
Cls
Print At 1,5, "Stoped"
EECON1.7 = 1
EWrite 100, [111]
While K_OK = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 10
Wend
L_Title = 14
DelayMS 1000
Finish = 0
T_H = 0
T_3H = 0
T_OV = 0
Menu = 0
GoTo Af_Stop
EndIf


If Motor_Bad = 14 Then GoSub Motor_Stop

If Finish = 1 Then GoTo Main

If Refresh = 1 Then
Refresh = 0
GoSub D_Show
EndIf

If Get = 1 Then
While RH_S = 1
Wend
RH_Count = Counter RH_S, 100
If RH_Count <= 100 Then
RH = 0
GoTo Here2
EndIf
If RH_Count >= 735 Then
RH = 0
RH_Const = 735
RH_Const2 = 735
ElseIf RH_Count <= 603 Then
RH = 100
RH_Const = 603
RH_Const2 = 618
ElseIf RH_Count <= 618 Then
RH = 90
RH_Const = 618
RH_Const2 = 633
ElseIf RH_Count <= 633 Then
RH = 80
RH_Const = 633
RH_Const2 = 646
ElseIf RH_Count <= 646 Then
RH = 70
RH_Const = 646
RH_Const2 = 660
ElseIf RH_Count <= 660 Then
RH = 60
RH_Const = 660
RH_Const2 = 672
ElseIf RH_Count <= 672 Then
RH = 50
RH_Const = 672
RH_Const2 = 685
ElseIf RH_Count <= 685 Then
RH = 40
RH_Const = 685
RH_Const2 = 697
ElseIf RH_Count <= 697 Then
RH = 30
RH_Const = 697
RH_Const2 = 710
ElseIf RH_Count <= 710 Then
RH = 20
RH_Const = 710
RH_Const2 = 724
ElseIf RH_Count <= 724 Then
RH = 10
RH_Const = 724
RH_Const2 = 724
EndIf

RH_Const2 = (RH_Const2 - RH_Const) / 10
RH_Count = (RH_Const - RH_Count) / RH_Const2
RH = RH + RH_Count

Here2:
Temp = ADIn 1
Temp_Sum = Temp_Sum + Temp
Inc Temp_C

If Temp_C >= 20 Then
Temp_C = 0
Temp = Temp_Sum / 20
Temp_Sum = 0
Get = 0
GoSub D_Show
GoTo Main
EndIf
DelayMS 2
GoTo Here2
EndIf

If Lock = 0 Then

If K_Sel = 0 Then
Dec Menu
GoSub effect
While K_Sel = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 50
Wend
DelayMS 50
If Menu = 0 Then
Out_S = 0
GoTo Be_Sel
EndIf
Refresh = 1
EndIf

Else
If K_Sel = 0 And K_OK = 0 Then
While K_Sel = 0 Or K_OK = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 50
Wend
Lock = 0
Lock_C = 0
Refresh = 1
GoTo Main
EndIf
EndIf


If K_OK = 0 And Menu = 1 Then
Inc Menu
GoSub effect
While K_OK = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 50
Wend
DelayMS 50
Refresh = 1
EndIf

If Menu = 2 And K_Sel = 0 Then
Menu = 1
GoSub effect
While K_Sel = 0
If Motor_Bad = 14 Then GoSub Motor_Stop
DelayMS 50
Wend
DelayMS 50
Refresh = 1
EndIf
GoTo Main

Disable
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Sensor Read SUB.
G_S_Int:
PIR1.0 = 0 : TMR1H = $0B : TMR1L = $DC

Inc T_OV
If T_OV = 25 Then Get = 1
If T_OV >= 50 Then ;10secs


;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Whole of Operations

If Ele_T = 1 And Temp >= Fix_Temp + 7 Then Ele_T = 0
If Ele_T = 0 And Temp <= Fix_Temp - 7 Then Ele_T = 1

If Ele_RH = 1 And RH >= Fix_RH + 5 Then Ele_RH = 0
If Ele_RH = 0 And RH <= Fix_RH - 5 Then Ele_RH = 1

Fan = Ele_T | Ele_RH

;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
T_OV = 0

If Finish = 0 Then Inc T_H
If T_H >= 1080 Then
Inc T_3H
Inc D1
If D1 = 8 Then D1 = 0
GoSub Get_Fix

If T_3H >= 168 Then
Cls
Print At 1,1, "Finished !"
Print At 2,1, "For New Task"
Print At 2,16, $7E
Finish = 1
Menu = 0
EndIf

EECON1.7 = 1
EWrite 100, [124]
DelayMS 5
EWrite 101, [L_Title]
DelayMS 5
EWrite 103, [T_3H]
DelayMS 5
EWrite 104, [D1]
DelayMS 5

If T_3H >= 120 Then
Code_ver = ERead 107
DelayMS 5
If Code_ver <> 99 Then
EECON1.7 = 1
EWrite 107, [140]
DelayMS 5
Ele_T = 0
Ele_RH = 0
Motor = 0
Fan = 0
Cls
GoTo Wr_Code
EndIf
EndIf

If T_3H <= Turn Then
Motor = 1
EECON1.7 = 1
Motor_Bad = 14
EWrite 105, [14]
DelayMS 5
While Motor_S = 1
DelayMS 20
Wend
EndIf

If Finish = 0 Then T_H = 0
EndIf
EndIf
Finished:
If Lock = 0 And K_OK = 1 And K_Sel = 1 And Menu <= 1 Then
Inc Lock_C
If Lock_C >= 100 Then
If Menu = 1 Then
Lock = 1
Else
Out_S = 1
EndIf
Lock_C = 0
EndIf
Else
Lock_C = 0
EndIf
Resume


'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Motor Control Sub


Get_Fix:
If T_3H >= Step2_Time Then
Fix_Temp = Step2_Temp
Fix_RH = Step2_RH
Else
Fix_Temp = Step1_Temp
Fix_RH = Step1_RH
EndIf

Return

;&&&&&&&&&&&&&&&&&&&&&&&&&&& Display Value on LCD
D_Show:
If Menu = 1 Then
EECON1.7 = 0
Print At 1, 1, CStr L_Title + 5000, " "
Print At 1,12, "D", Dec (T_3H / 8) + 1,".", Dec D1," "
Print At 2, 3, Dec RH, "% "
Print At 2, 7, "-"
Print At 2, 9, Dec Temp / 10 ,".", Dec Temp Dig 0, $DF, "C "

If Lock = 0 Then
Print At 2,1, $7F, " "
Else
Print At 2,1, 0," "
EndIf

Print At 2,16, $7E

EndIf

If Menu = 2 Then
Print At 1,1, "Remined:", Dec ((168 - T_3H) / 8)," Days "
Print At 2,1, $7F, " ", "Fix:", Dec Fix_RH, "% ", Dec Fix_Temp /10, ".", Dec Fix_Temp Dig 0, $DF, "C "
EndIf

Return


Motor_Stop:
If Motor_S = 1 Then
Motor = 0
Motor_Bad = 0
EECON1.7 = 1
EWrite 105, [0]
DelayMS 10
EndIf

Return

effect:
K_Hold = 0 'it's local variable

ef:
Print At 1, 16 - K_Hold, "*"
Print At 2, K_Hold, "*"
DelayMS 20
Inc K_Hold
If K_Hold = 17 Then
K_Hold = 0
Return
EndIf
GoTo ef


Get_TRH:
While RH_S = 1
Wend
RH_Count = Counter RH_S, 8
RH = RH_Count

Here:
Temp = ADIn 1
Temp_Sum = Temp_Sum + Temp
Inc Temp_C

If Temp_C >= 20 Then
Temp_C = 0
Temp = Temp_Sum / 20
Temp_Sum = 0
Return
EndIf
GoTo Here


Get_Value:
If L_Title = 14 Then ;Morq
Step1_Temp = 375 : Step1_RH = 60
Step2_Time = 144 : Step2_Temp = 365 : Step2_RH = 65
Turn = 112

ElseIf L_Title = 28 Then ;Ordak
Step1_Temp = 375 : Step1_RH = 70
Step2_Time = 112 : Step2_Temp = 385 : Step2_RH = 60
Turn = 112

ElseIf L_Title = 42 Then ;Qaz
Step1_Temp = 375 : Step1_RH = 70
Step2_Time = 112 : Step2_Temp = 385 : Step2_RH = 60
Turn = 112

ElseIf L_Title = 56 Then ;Kabk
Step1_Temp = 375 : Step1_RH = 70
Step2_Time = 112 : Step2_Temp = 385 : Step2_RH = 60
Turn = 112

ElseIf L_Title = 70 Then ;Shotormorq
Step1_Temp = 200 : Step1_RH = 70
Step2_Time = 112 : Step2_Temp = 385 : Step2_RH = 60
Turn = 112

ElseIf L_Title = 84 Then ;Belderchin
Step1_Temp = 375 : Step1_RH = 70
Step2_Time = 112 : Step2_Temp = 385 : Step2_RH = 60
Turn = 112

ElseIf L_Title = 98 Then ;Qarqavol
Step1_Temp = 375 : Step1_RH = 70
Step2_Time = 112 : Step2_Temp = 385 : Step2_RH = 60
Turn = 112

ElseIf L_Title = 112 Then ;Boqalamun
Step1_Temp = 377 : Step1_RH = 70
Step2_Time = 112 : Step2_Temp = 385 : Step2_RH = 60
Turn = 112
Else
Step1_Temp = 0 : Step1_RH = 0
Step2_Time = 0 : Step2_Temp = 0 : Step2_RH = 0
Turn = 0
EndIf
Return


Org 5000
CData "<No Item>",0
Org 5014
CData "Morq",0
Org 5028
CData "Ordak",0
Org 5042
CData "Qaz",0
Org 5056
CData "Kabk",0
Org 5070
CData "Shotormorq",0
Org 5084
CData "Belderchin",0
Org 5098
CData "Qarqavol",0
Org 5112
CData "Boqalamun",0
Org 5126
CData "Jooje TalaSupport:+98936-726-2016",0
Org 5160
CData "Welcome",0
Org 5170
CData "Design & Run:Ali Hosseiny",0




you can simulate this project on proteus get it here (http://www.mediafire.com/?doki8ec87b26qss)

Les
1st February 2012, 15:05
I don't quite understand the statement "Here is my project (Egg incubator) with Proton IDE & 876A for free"

How is it free?

The original LITE version of the compiler did not support the 16F876A, and certainly did not allow that many lines of code.

Kapitan
1st February 2012, 16:05
I think he is just having a yoke :)

'Free' is as in the context of - a google search and simple download.

Unfortunately................

Alee
1st February 2012, 19:33
I don't quite understand the statement "Here is my project (Egg incubator) with Proton IDE & 876A for free"

How is it free?

The original LITE version of the compiler did not support the 16F876A, and certainly did not allow that many lines of code.

i forgot to write "u can see this code free" after publish i saw but didn't know how can edit this wrong statement, sorry !

Alee
1st February 2012, 19:42
I think he is just having a yoke :)

'Free' is as in the context of - a google search and simple download.

Unfortunately................

My english may not very good but you should be more polite, i just want to report error may it was your problem when using CData & EEPROM together my thread was about EECON1 Register not about statements or english learning.:semi-twins:

Les
1st February 2012, 20:32
What version of the compiler are you using, as a possible anomaly may have been corrected in subsequent updates.