| CODE |
' Control: ' System starts im Receivermodus ' Displays Chanal with value ' DMX conected to pin PD0 (later PD1 will be used to transmit ' A matrix keyboard is conected on porta 0-7 for a 4x4 keyboard ' LCD in 4 bit modus ' by pressing Chanel key ' we can type chanel number what we would like to see ' by pressing chanel key twice program starts to look for active chanels ' chanel up key ' chanel down key ' esc key leave mode ' ' pressing data key in transmitter mode ' pressing once 0-255 ' pressing twice Data 0-100 ' pressing 3 times Data via ADC Pot ' again same keys avaialable ' 0-9 typing info ' chanel up ' chanel down ' ' pressing enter will show menu ' ESC aborts ' ' keyboard: ' 0-9 ' Enter ' ESC ' + ' - ' Chanel ' Data ' ' Display 4x20 ' Receive mode transmit ' 12345678901234567890 12345678901234567890 ' 1 Chanel: xxx/XXX KANAL: XXX - XXX ' 2 value BINAER : XXX 255 X x _Xx X ' 3 Persent: XXX 0 XxX_xxXXX______X ' 4 Status ' ' ************************************************************ ' ****** Programm ' ************************************************************ $crystal = 8000000 $baud = 250000 Config Kbd = Porta , Debounce = 20 , Delay = 50 Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.0 , Rs = Portc.1 Config Lcd = 20 * 4 Config Pinb.7 = Output Config Pinb.6 = Output Config Pinb.1 = Output Config Pinb.0 = Output 'Config Adc = Single , Prescaler = Auto 'Not yet used (for transmitter) Config Timer2 = Timer , Prescale = 1024 'timer For uart Dim Recval As Byte ' DMX data Dim Status As Byte ' Statusbyte Dim Modus As Byte ' 0 = Receiver, 1 = Transmitter Dim Aktmodus As Byte ' Active mode Dim Dmx_data As Byte ' DMX Data from displayed Chanal 0-255 Dim Proval As Integer ' DMX Data in prosent 0-100 Dim Tempchannel As Integer ' Inserted Chanel Dim Viewchannel As Integer ' Displayed Chanel Dim Keyval As Byte ' Pressed button Dim Oldkey As Byte ' Old pressed button Dim Univers As Byte ' Universumsnumber Dim Max_dmx_data As Integer ' Maximum send Chanels Dim Dmx_count As Integer ' Start counter DMX Dim X As Integer ' help variable Dim Temp As Integer ' Help variable Dim View_val As Integer ' Dim Waittime As Integer ' Dim View_string As String * 6 ' String with value Dim Num_row As Byte Dim Num_col As Byte Dim Num_min As Integer Dim Num_max As Integer Dim Num_len As Byte Dim Num_flags As Byte Dim Num_wert As Integer Dim Num_string As String * 6 Dim Num_temp As Integer Num_start Alias Num_flags.0 Num_end Alias Num_flags.1 Num_error Alias Num_flags.7 Dec_key Alias 10 Inc_key Alias 11 Data_key Alias 14 Channel_key Alias 13 Esc_key Alias 12 Enter_key Alias 15 Receive Alias 1 ' Receiver modus Transmit Alias 2 ' Transmit modus Menu Alias 255 ' Menu modus Foundflag Alias Status.0 ' Value found Searchflag Alias Status.1 ' Value searching Waitflag Alias Status.2 ' Value wait for search resuld View Alias Status.3 Yes Alias 1 No Alias 0 Rs485_dir Alias Portb.0 ' Way of 75176 Lcd_light Alias Portb.1 Buzzer Alias Portb.7 ' Beeper Alias Dmx_led Alias Portb.6 Cls Cursor Off Noblink Set Lcd_light Set Dmx_led Lcd " DMX-TESTER V0.1" Locate 2 , 1 Lcd " (C) me now " Locate 3 , 1 Lcd "Hope it will to work" For Temp = 1 To 10 Toggle Lcd_light Toggle Dmx_led Waitms 500 Next X Locate 4 , 1 Lcd " Press any key" Sound Buzzer , 250 , 600 Do Loop Until Getkbd() <> 16 Sound Buzzer , 100 , 100 Modus = Receive View = Yes Aktmodus = 0 Tempchannel = 0 Viewchannel = 1 Univers = 0 Max_dmx_data = 0 Set Ucr.chr9 ' 9 Bit as 2 Stopbits On Timer2 Timer_int On Urxc Dmx_receive ' Interruptroutine for receiving Enable Timer2 ' enable the timer interrupt Enable Urxc Enable Interrupts ' ###### Master Routine ###### Do If Lcd_light = 1 Then ' When LCD light and time If Waittime > 300 Then Reset Lcd_light ' LCD light off End If If Modus <> Aktmodus Then ' Modus gechaned Cls ' clear LCD If Modus = Receive Then ' Receiver mode Reset Rs485_dir Set Ucr.rxen ' Switch to Receiving Lcd "CHANEL:" Locate 2 , 1 Lcd "VALUE: b %" Elseif Modus = Transmit Then ' Sendemodus Transmit: 'Transmitter Set Rs485_dir Reset Ucr.rxen Lcd "CHANEL:" Locate 2 , 1 Lcd "VALUE: b %" Elseif Modus = Menu Then ' Menu modus Menu: Reset Rs485_dir Reset Ucr.rxen Lcd "1 Receiver 1 Chanel" Locate 2 , 1 Lcd "2 Receiver 16 Chanel" Locate 3 , 1 Lcd "3 Transmitter" End If Aktmodus = Modus End If If Modus = Receive Then ' Receiver If View = Yes Then ' When display wanted Locate 1 , 7 View_val = Viewchannel Gosub Using Lcd View_string; "/" View_val = Max_dmx_data Gosub Using Lcd View_string Locate 2 , 7 View_val = Dmx_data Gosub Using Lcd View_string Locate 2 , 13 Proval = 100 * Dmx_data Proval = Proval / 255 View_val = Proval Gosub Using Lcd View_string Cursor Off Locate 4 , 1 Lcd " " End If Keyval = Getkbd() ' Read keyboard If Keyval <> Oldkey Then Oldkey = Keyval If Keyval <> 16 Then Sound Buzzer , 60 , 100 Set Lcd_light Waittime = 0 End If Keyval = Lookup(keyval , Keypad) ' Look in Tabel for Select Case Keyval Case 255 ' No key Pressed ' do nothing Case Esc_key ' ESC Aborts Set View Num_flags = 0 Reset Searchflag Reset Waitflag Reset Num_start Case Data_key If Modus = Receive Then Modus = Transmit Elseif Modus = Transmit Then Modus = Receive End If Case Dec_key ' Count chanel down Decr Viewchannel If Viewchannel < 1 Then Viewchannel = Max_dmx_data Case Inc_key ' Count chanel up Incr Viewchannel If Viewchannel > Max_dmx_data Then Viewchannel = 1 Case Channel_key ' Chanel key pressed If Num_start = 0 Then ' Activate Key insert Locate 4 , 1 ' Search Lcd "Please give chanel" Num_row = 1 Num_col = 7 Num_min = 1 Num_max = Max_dmx_data Num_len = 3 Gosub Numinput Else ' Find data If Max_dmx_data > 0 Then ' If there is data Tempchannel = Viewchannel ' Remembeer where we where Incr Viewchannel ' go search next chanel If Viewchannel > Max_dmx_data Then Viewchannel = 1 Cursor Off ' Cursor off Locate 4 , 1 ' Go Search Lcd "Searching... " Set Waitflag ' Set Flags Set Searchflag Reset Num_start Else 'Beep Fail Sound Buzzer , 250 , 350 End If End If Case Enter_key If Num_start = 1 Then ' Enter pressed Gosub Numinput If Num_end = 1 Then If Num_error = 0 Then Viewchannel = Num_wert Else 'Beep_fail Sound Buzzer , 150 , 350 End If Num_flags = 0 End If End If Case Else ' Number key pressed If Num_start = 1 Then Gosub Numinput End Select End If 'Search protocol If Waitflag = 1 Then ' When we wait for a value If Searchflag = 0 Then ' and search ended If Foundflag = 1 Then ' and some thing was found ' Beep_ok ' Then tell Sound Buzzer , 100 , 400 Waitms 100 Sound Buzzer , 100 , 400 Else ' Else ' Beep_fail ' Pitty Sound Buzzer , 150 , 350 Viewchannel = Tempchannel ' And back where we came from End If Reset Waitflag ' and abort waiting Set View End If End If End If Loop '######################################################################### '### Sub routinen '######################################################################### ' Format number display Using: View_string = " " + Str(view_val) View_string = Right(view_string , 3) Return ' Number input Numinput: If Num_start = 0 Then Set Num_start Reset View Num_string = "" Locate Num_row , Num_col Lcd String(num_len , 32) Locate Num_row , Num_col Cursor On Blink Else If Keyval = Enter_key Then Num_wert = Val(num_string) If Num_wert < Num_min Then Set Num_error If Num_wert > Num_max Then Set Num_error Set Num_end Set View Else If Len(num_string) < Num_len Then Num_string = Num_string + Str(keyval) Locate Num_row , Num_col Lcd Num_string Else Sound Buzzer , 150 , 350 End If End If End If Return '######################################################################### '### Interruptroutine '######################################################################### ' ### Interrupthandling for serial receiving ### Dmx_receive: Recval = Udr If Usr.or = 1 Then ' Overrun Error Reset Dmx_led Dmx_count = -2 Elseif Usr.fe = 1 Then ' Break detected by Framing Error If Ucr.rxb8 = 0 Then ' and 9.Bit = 0 Max_dmx_data = Dmx_count - 1 Reset Dmx_led Dmx_count = 0 End If Elseif Dmx_count = -1 Then 'When ready If Recval = Univers Then ' And Startcode = Univers 0 Set Dmx_led ' Than tell Dmx_count = 0 ' and Counter to zero Else Reset Dmx_led ' Wrong Universum, LED off Dmx_count = -2 ' Try again End If Elseif Dmx_count >= 0 Then ' receiving data Incr Dmx_count ' Chanel counter + 1 If Viewchannel = Dmx_count Then ' if wanted Chanel then Dmx_data = Recval ' and give Variable If Searchflag = 1 Then ' when we are Searching If Recval > 0 Then ' and value = > 0 Set Foundflag ' then tell: found Reset Searchflag ' and quit search Else ' if stil nothing Incr Viewchannel ' count chanel up If Viewchannel > Max_dmx_data Then Viewchannel = 1 ' only till max. MaxDMXData If Viewchannel = Tempchannel Then ' then restart at 1 Reset Foundflag ' tell nothing found Reset Searchflag ' and quit search End If End If End If End If End If Return ' ### Interrupt für wait routine Timer_int: Incr Waittime Return End 'end program ' Keypad info Keypad: Data 1 , 4 , 7 , 10 Data 2 , 5 , 8 , 0 Data 3 , 6 , 9 , 11 Data 12 , 13 , 14 , 15 Data 255 |