104 lines
2.4 KiB
Plaintext
104 lines
2.4 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC16F886
|
|
' ########### end ###########
|
|
|
|
; FILE: LED Colour control 16F886.gcb
|
|
; DATE: 31.01.2015
|
|
; VERSION: 1.0a
|
|
; AUTHOR: Evan R. Venn based on works of Hugh Considine
|
|
;
|
|
; Description.
|
|
' A demostration program for GCGB and GCB.
|
|
' Program controls the color of Tri-colour LED by the value of ANO
|
|
' The attached LCD is used to show introduction text only.
|
|
|
|
|
|
; This file is part of the Great Cow Basic compiler.
|
|
;
|
|
; This demonstration code is distributed in the hope that it will be useful,
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
; GNU General Public License for more details.
|
|
;
|
|
; ----- Configuration
|
|
|
|
#chip 16F886,16
|
|
|
|
|
|
; ----- Define Hardware settings
|
|
'LED port directions
|
|
dir Red out
|
|
dir green out
|
|
dir blue out
|
|
|
|
; ----- Constants
|
|
; LCD setup
|
|
#define LCD_IO 8
|
|
#define LCD_DATA_PORT PORTC
|
|
#define LCD_RS PORTD.0
|
|
#define LCD_RW PORTD.1
|
|
#define LCD_Enable PORTD.2
|
|
|
|
'LED pins
|
|
#define Red PORTB.2
|
|
#define Green PORTB.1
|
|
#define Blue PORTB.0
|
|
|
|
; ----- Variables
|
|
'Calculation Variable
|
|
Dim CalcTemp As Word
|
|
|
|
|
|
; ----- Main body of program commences here.
|
|
'Intro message
|
|
; LCD Layout
|
|
' 1234567890123456
|
|
PRINT "Tri-colour LED:"
|
|
locate 1,1
|
|
PRINT "A GCBASIC Demo"
|
|
Wait 2 sec
|
|
|
|
Main:
|
|
Hue = ReadAD(AN0)
|
|
If Hue < 20 Then Hue = 20
|
|
If Hue > 240 Then Hue = 240
|
|
Hue = Hue - 20
|
|
RInt = 0
|
|
GInt = 0
|
|
BInt = 0
|
|
If Hue < 220 And Hue > 150 Then
|
|
CalcTemp = ((220 - Hue) * 171) / 100
|
|
BInt = CalcTemp
|
|
CalcTemp = ((Hue - 150) * 286) / 100
|
|
RInt = CalcTemp
|
|
End If
|
|
If Hue < 150 And Hue > 120 Then
|
|
GInt = (150 - Hue) * 4
|
|
BInt = (Hue - 120) * 4
|
|
End If
|
|
If Hue < 120 Then
|
|
CalcTemp = ((120 - Hue) * 167)/100
|
|
RInt = CalcTemp
|
|
GInt = Hue
|
|
End If
|
|
ShowColour(RInt,GInt,BInt)
|
|
goto Main
|
|
|
|
end
|
|
|
|
; ----- Support methods. Subroutines and Functions
|
|
|
|
sub ShowColour(RL, GL, BL)
|
|
RLTemp = RL+RL
|
|
FlashRate = ReadAD(AN0)
|
|
for PulseLoop = 1 to FlashRate
|
|
set red on
|
|
set green on
|
|
set blue on
|
|
for Level = 1 to 200
|
|
if Level > RLTemp then set red off
|
|
if Level > GL then set green off
|
|
if Level > BL then set blue off
|
|
next
|
|
next
|
|
end sub |