
' **********************************************************************
' * File:   Bluetooth_2013.bas   - Progetto Del Del 04.05.13 By Max B : *
' * Scheda: ARDUINO UNO       con Bascom AVR   IDE
' *  ver. n del 04052013
' **********************************************************************
'
'****************** Direttive del compilatore **************************
'
$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 9600
Config Clockdiv = 2
 $timeout = 300000
'$sim
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
'Config Timer2 = Pwm , Prescale = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
Config Adc = Single , Prescaler = Auto , Reference = Avcc       'configura ADC

'****************** Dichiarazione delle variabili **********************
Dim N As Byte
Dim Var As String * 1
Dim Su As Byte
Dim Giu As Byte
Dim Tempo As Word
Dim Dist As Word
Dim X As String * 2
Dim V As Word
Dim V1 As Word
Dim Temp As Single
Dim S5 As String * 5

Declare Sub Inizializ()
'************************* Programma main ******************************
Mai:
   Call Inizializ()
     Portb.0 = 1 : Portb.1 = 1 : Portb.2 = 1 : Portb.4 = 1 : Portb.5 = 1
     Portd.4 = 1 : Portd.6 = 1 : Portd.7 = 1
     Cls : Cursor Off                             'Inizializza LCD
   Lcd "  TEST MODULO   "
   Lowerline : Lcd "BLUETOOTH"
   Print "TEST MODULO BLUETOOTH   "
   Wait 2
   Cls
Avvio:
   Cls
   Print "AVVIA TEST "
   Upperline
    Lcd "  AVVIA TEST  "
   Lowerline : Lcd "           By MaxB"

 Via:
   Input , X Noecho
      If X = "t" Then : Goto Test
       Elseif X = "u" Then : Goto Resetprog
      Elseif X = "r" Then : Goto Temperatura
      Elseif X = "w" Then : Goto Resetprog
      Elseif X = "y" Then : Goto Avvio

     Elseif X = "k" Then : Reset Portb.0 : Cls : Upperline : Lcd " ...in funzione " : Lowerline : Lcd "Accensione Lampada " : Print "Accensione Lampada"
     Elseif X = "l" Then : Set Portb.0 : Cls : Upperline : Lcd " ...in funzione" : Lowerline : Lcd " Spegnimento Lampada" : Print "Spegnimento Lampada "
     Elseif X = "i" Then : Reset Portb.1 : Cls : Upperline : Lcd " ...in funzione" : Lowerline : Lcd "Accensione Router " : Print "Accensione Router"
     Elseif X = "j" Then : Set Portb.1 : Cls : Upperline : Lcd " ...in funzione" : Lowerline : Lcd " Spegnimento Router" : Print "Spegnimento Router "
     Elseif X = "g" Then : Reset Portb.2 : Cls : Upperline : Lcd " ...in funzione" : Lowerline : Lcd "Accensione Mp3 " : Print "Accensione Mp3"
     Elseif X = "h" Then : Set Portb.2 : Cls : Upperline : Lcd " ...in funzione" : Lowerline : Lcd " Spegnimento Mp3" : Print "Spegnimento Mp3 "
      Elseif X = "c" Then : Reset Portb.4 : Cls : Upperline : Lcd " ...in funzione" : Lowerline : Lcd "Accensione Luci " : Print "Accensione Luci"
     Elseif X = "d" Then : Set Portb.4 : Cls : Upperline : Lcd " ...in funzione" : Lowerline : Lcd " Spegnimento Luci" : Print "Spegnimento Luci "
     Goto Avvio
      End If


Test:
Cls
Lcd "Test comandi  ON"
Print "Test comandi  ON"
 Reset Portb.0
 Waitms 700
Set Portb.0
 Waitms 500
  Reset Portb.1
 Waitms 700
Set Portb.1
 Waitms 500
  Reset Portb.2
 Waitms 700
Set Portb.02
 Waitms 500
  Reset Portb.4
 Waitms 700
Set Portb.4
 Waitms 500
 Cls
Waitms 400
Lcd "Test comandi OFF"
Print "Test comandi OFF"
Waitms 300
Print " " ;
Waitms 200
Goto Avvio

Resetprog:
             Set Portb.0
               Set Portb.1
              Set Portb.2
             Set Portb.4
                Cls : Lcd "RESET  "
             Lowerline : Lcd "    COMANDI "
             Print "RESET COMANDI"
             Wait 1
Goto Avvio

Temperatura:
Start Adc                                         'start ADC
 Ddrc.0 = 0                                       ' imposta il portc.0 come input
 Waitms 10
 V = Getadc(0) : V1 = 0                           'leggi dal canale (0)
 V1 = Getadc(0)
 V = V + V1 : V1 = 0                              ' 2 letture
Temp = 2026 - V
Temp = Temp / 5.1                                 'resistenz a +5V di 5760 ohm (4700+470) - termistore di 47Kohm
 S5 = Fusing(temp , "##.#")
 V = 0
 Ddrc.0 = 1
 Cls
 Upperline
 Lcd "Temp. Int.Quadro" : Print " Temperatura :"
 Locate 2 , 5
 Lcd S5 ; " " ; Chr(176) ; "C "
 Print S5 ; "  " ; "" ; "C"
 Wait 3
 Print " " ;
 Waitms 500
 Goto Avvio

  End

  Sub Inizializ()
     Disable Interrupts
     Ddrb = Ddrb Or &H3F                          ' Imposta PB0- PB1-PB2-PB3-PB4-PB5 come output
     Ddrd = Ddrd Or &HF4                          'Imposta PD2- PD4-PD5-PD6-PD7 come output
      Ddrd.3 = 0                                  'imposta PD3 come INPUT
     '  Ddrd.4 = 1                                 ' imposta PD4 come OUTPUT
     'Ddrc = Ddrc And Hc0                          'imposta PCO ,1,2,3,4,5 come INPUT
 End Sub