' ******************************************************************************
' * Title         : Exp.08.bas                                                 *
' * Target Board  : Mini-Phoenix - REV 1.00                                    *
' * Target MCU    : ATMega32A                                                  *
' * Author        : Walid Balid                                                *
' * IDE           : BASCOM AVR 2.0.7.3                                         *
' * Peripherals   : Pull-Up Resistors                                          *
' * Description   : GPIOs as Input; Active Low (GND)                           *
' ******************************************************************************
' Set the SW Jumbers to GND (Active Low)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'-----------------------[Definitions]
$regfile = "m32def.dat"
$crystal = 8000000
$baud = 9600
'-----------------------
'-----------------------[GPIO Configurations]
Config Portc = &B00000111
Led1 Alias Portc.: Led2 Alias Portc.: Led3 Alias Portc.2
Set Led1 : Set Led2 : Set Led3

Config Pind.= Input : Sw_1 Alias Pind.: Portd.= 1     'PU Internal Resistor
Config Pind.= Input : Sw_2 Alias Pind.: Portd.= 1
Config Pinb.= Input : Sw_3 Alias Pinb.: Portb.= 1
'-----------------------
'-----------------------[Variables]
Dim Count1 As Byte , Count2 As Byte , Count3 As Byte
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'--->[Main Program]
Print "Hello!"
Do
   If Sw_1 = 0 Then Gosub Sw_r1
   If Sw_2 = 0 Then Gosub Sw_r2
   If Sw_3 = 0 Then Gosub Sw_r3
Loop
End
'---<[End Main]
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'--->[Print]
Sw_r1:
   Toggle Led1 : Count1 = Count1 + 1
   Print "Sw1 has Pressed! > " ; Count1
Return
'---<
Sw_r2:
   Toggle Led2 : Count2 = Count2 + 1
   Print "Sw2 has Pressed! > " ; Count2
Return
'---<
Sw_r3:
   Toggle Led3 : Count3 = Count3 + 1
   Print "Sw3 has Pressed! > " ; Count3
Return
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~