menue+eigene threads Kategorie: Programmierung Basic (von dirk - 4.08.2009 23:33) | ||
| ||
hallo, moechte ein kleines demoprog.(basic) zur verfügung stellen. darin sind eigene quasi-threads vorhanden. eine menuefuehrung wird mit einem poti umgesetzt. die aktualisierungsgeschwindigkeit vom lcddisplay wird je nach menue flexibel angepasst. für verbesserungen oder hinweise waere ich dankbar. :-) Quellcode '******************************************************************************* Dim sel_men As Byte Dim st1 As Byte Dim st2 As Byte Dim cnt1 As Byte Dim u2 As Byte Dim cnt2 As Byte Dim cnt2_speed As Byte 'Dim Tnom As Word 'Dim Sensor1 As Single Dim u1 As Single Dim r1 As Single Dim temp1 As Single Dim sw1_CHR(9) As Char Dim sw2_CHR(9) As Char Dim t1(9) As Char 'Dim t2(9) As Char '******************************************************************************* Sub mid_fast_things() Select Case st1 Case 1 Port_WriteBit(PORT_LED1,PORT_OFF) st1=0 Case 0 Port_WriteBit(PORT_LED1,PORT_ON) st1=1 End Select Select Case Port_ReadBit(PORT_SW1) Case 0 'LCD_CursorPos(&H40) 'LCD_WriteText("T1 : ON ") 'Port_WriteBit(PORT_LED1,PORT_ON) sw1_CHR = "SW1: ON " Case 1 'LCD_CursorPos(&H40) 'LCD_WriteText("T1 : OFF") 'Port_WriteBit(PORT_LED1,PORT_OFF) sw1_CHR = "SW1: OFF" End Select Select Case Port_ReadBit(PORT_SW2) Case 0 'LCD_CursorPos(&H0) 'LCD_WriteText("T2 : ON ") sw2_CHR = "SW2: ON " Case 1 'LCD_CursorPos(&H0) 'LCD_WriteText("T2 : OFF") sw2_CHR = "SW2: OFF" End Select End Sub '******************************************************************************* Sub slow_things() Select Case st2 Case 1 Port_WriteBit(PORT_LED2,PORT_OFF) st2=0 Case 0 Port_WriteBit(PORT_LED2,PORT_ON) st2=1 End Select ADC_Set(ADC_VREF_VCC,ADC1) u2=round(5*ADC_Read()/1024.0) Select Case u2 Case 0 To 1 cnt2_speed=199 sel_men=sel_men+1 Case 1 To 2 cnt2_speed=49 sel_men=1 Case 2 To 3 sel_men=2 cnt2_speed=49 Case 4 To 5 sel_men=3 cnt2_speed=49 End Select Select Case sel_men Case 1 LCD_CursorPos(&H0) LCD_WriteText("ATMEG128") LCD_CursorPos(&H40) LCD_WriteText(" DEMO ") 'Str_WriteFloat(u2,1,t2,0) 'LCD_WriteText(t2) 'Menue-Wert Case 2 LCD_CursorPos(&H0) LCD_WriteText(sw2_CHR) LCD_CursorPos(&H40) LCD_WriteText(sw1_CHR) Case 3 LCD_CursorPos(&H0) LCD_WriteText("NTCSENS:") 'Sensor1=ADC_Read() ADC_Set(ADC_VREF_VCC,ADC0) u1=5*ADC_Read()/1024.0 r1=5.0/u1-1.0 'Temp1=(1.0/(1.0/3435.0*ln(Tnom/Sensor1)+(1.0/298.0)))-273.0 'brechnung c-co-pro temp1=1000.0/(ln(r1)/3.435+1000.0/298.0)-274.0 'berechnung aus c-control II Str_WriteFloat(temp1,1,t1,0) LCD_CursorPos(&H40) 'LCD_WriteChar(0x53) 'S 'LCD_WriteChar(0x31) '1 'LCD_WriteChar(0x20) 'Space 'LCD_WriteChar(0x3A) ': 'LCD_WriteChar(0x20) 'Space LCD_WriteChar(0x20) 'Space LCD_WriteText(t1) 'Temperatur-Wert 'LCD_WriteChar(0x20) 'Space LCD_WriteChar(0xDF) '° LCD_WriteChar(0x43) 'C LCD_WriteChar(0x20) 'Space sel_men=0 End Select End Sub '******************************************************************************* Sub int_10ms() Dim irqcnt As Integer cnt1=cnt1+1 cnt2=cnt2+1 If cnt1>= 19 Then cnt1=0 mid_fast_things() End If If cnt2>= cnt2_speed Then cnt2=0 slow_things() End If irqcnt=Irq_GetCount(INT_TIM2COMP) End Sub '******************************************************************************* Sub ini() sel_men=0 st1=0 st2=0 cnt2_speed=199 Port_DataDirBit(PORT_SW1,PORT_IN) Port_DataDirBit(PORT_SW2,PORT_IN) Port_WriteBit(PORT_SW1,PORT_OFF) 'Pull Up set Port_WriteBit(PORT_SW2,PORT_OFF) 'Pull Up set Port_WriteBit(PORT_LED1,PORT_OFF) Port_WriteBit(PORT_LED2,PORT_OFF) Port_DataDirBit(PORT_LED1,PORT_OUT) Port_DataDirBit(PORT_LED2,PORT_OUT) 'Tnom=560.0 LCD_Init() LCD_ClearLCD() LCD_CursorOff() LCD_WriteText("C-Co-Pro") LCD_CursorPos(&H40) LCD_WriteText(" CONRAD ") 'AbsDelay(1000) End Sub '******************************************************************************* Sub main() ini() Irq_SetVect(INT_TIM2COMP,int_10ms) Do While(1):End While End Sub '******************************************************************************* | ||
Antwort schreiben Antworten: |
Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum