-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atmega32 + LDR + 16x2 Character lcd display.bas
69 lines (52 loc) · 1.55 KB
/
Atmega32 + LDR + 16x2 Character lcd display.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'======================================================================='
' Title: LCD Display LDR Controller
' Last Updated : 01.2022
' Author : A.Hossein.Khalilian
' Program code : BASCOM-AVR 2.0.8.5
' Hardware req. : Atmega32 + LDR + 16x2 Character lcd display
'======================================================================='
$regfile = "m16def.dat"
$crystal = 1000000
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.2 , Rs = Portb.0
Config Lcd = 16 * 2
Cursor Off
Cls
Enable Interrupts
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Config Portc.1 = Output
Reset Portc.1
Relay Alias Portc.1
Dim Ldr As Word
Dim Setpoint As Word
Dim Setpoint_max As Word
Dim Setpoint_min As Word
'-----------------------------------------------------------
Do
Gosub Red_temp
Gosub Show_temp
Gosub Termostat
Waitms 300
Loop
End
'-----------------------------------------------------------
Red_temp:
Ldr = Getadc(7) : Ldr = Ldr * 4.8828125
Setpoint = Getadc(6) : Setpoint = Setpoint * 4.8828125
Return
''''''''''''''''''''''''''''''
Show_temp:
Locate 1 , 1 : Lcd "LDR:" ; Ldr ; " mV"
Locate 2 , 1 : Lcd "Setpoint:" ; Setpoint ; " mV"
Return
''''''''''''''''''''''''''''''
Termostat:
Setpoint_max = Setpoint
Setpoint_min = Setpoint - 10
If Ldr > Setpoint_max Then
Reset Relay
Elseif Ldr <= Setpoint_min Then
Set Relay
End If
Return
'-----------------------------------------------------------