104 lines
2.4 KiB
Plaintext
104 lines
2.4 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC16F886
|
|
' ########### end ###########
|
|
|
|
; FILE: LED Tri-Colour change 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 drives Tri-colour LED.
|
|
' 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
|
|
|
|
#define Red PORTB.2
|
|
#define Green PORTB.1
|
|
#define Blue PORTB.0
|
|
|
|
; ----- Variables
|
|
' No Variables specified in this example. All byte variables are defined upon use.
|
|
|
|
|
|
|
|
; ----- Main body of program commences here.
|
|
'Intro message
|
|
PRINT "Tri-colour LED:"
|
|
Locate 1, 1
|
|
PRINT "A GCBASIC Demo"
|
|
Wait 2 sec
|
|
Main:
|
|
For RedLevel = 1 to 200
|
|
ShowColour Smooth(RedLevel), 1, 1
|
|
next
|
|
For GreenLevel = 1 to 200
|
|
ShowColour 1, Smooth(GreenLevel), 1
|
|
next
|
|
For BlueLevel = 1 to 200
|
|
ShowColour 1, 1, Smooth(BlueLevel)
|
|
next
|
|
goto Main
|
|
end
|
|
|
|
; ----- Support methods. Subroutines and Functions
|
|
|
|
|
|
sub ShowColour(RL, GL, BL)
|
|
RLTemp = RL+RL
|
|
' You can use 0 [zero], or ADC0 or ANO they are mapped to the correct analog port.
|
|
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
|
|
end if
|
|
if Level > GL then
|
|
set green off
|
|
end if
|
|
if Level > BL then
|
|
set blue off
|
|
end if
|
|
next
|
|
next
|
|
end sub
|
|
|
|
function Smooth(temp)
|
|
if temp < 100 then
|
|
Smooth = temp
|
|
end if
|
|
if temp >= 100 then
|
|
Smooth = 200-temp
|
|
end if
|
|
end sub
|
|
|