Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20563

BASCOM-AVR : Clock,Date and Temperature, using atmega8..bascom code. : NEWTOPIC

$
0
0
Hy I want to make a clock with ATMEGA8 and 7-segment display. But this code does not contain the date, I need to place and time, but I do not know ... I can Juta someone? I can rewrite the code or give me someone else to be in all the above implemented. If you do not pray that other code to it, if it can display the time for 35 seconds, the time and temperature for 5 seconds each. Thank you. [code:1:1a06e7ac5b] $regfile = "m8def.dat" $crystal = 4000000 $hwstack = 40 $swstack = 16 $framesize = 32 Config Submode = New 'Configurare Timer0 pentru frecventa de multiplexare de 4ms Config Timer0 = Timer , Prescale = 64 On Ovf0 , Tmr0_isr Enable Ovf0 Start Timer0 Const Dif = 5 / 1024 Const Volt_div = 1 Config Adc = Single , Prescaler = Auto , Reference = Avcc Start Adc Config Clock = Soft , Gosub = Sectic 'Use the softclock, 32.768KHz crystal connected to tosc1/2 Time$ = "12:30" 'ceasul setat initial la 12:30 Digit Alias Portd 'iesirea de digiti la PORTD Config Digit = Output Ddrb = &B00001111 'PORTB<0-3> setat ca iesiri multiplexate Ddrc = &H00 'PORTC setat ca intrare Button_hr Alias Pinc.0 'butonul de reglaj ore pe PORTC.0 Button_min Alias Pinc.1 'butonul de reglaj minute pe PORTC.1 Set Portc.0 'Pull-UP butoane Set Portc.1 Lm35 Alias Pinc.2 'senzorul de temperatura pe PINC.2 Dim Adc2 As Word 'tensiunea de pe intrarea ADC2 Dim Temp As Word 'cuvantul care tine temperatura Dim Tem As Byte Dim T As Byte : T = 0 'timer de afisare Dim Afisare As Byte : Afisare = 0 Dim Cifra As Byte 'Presetare digiti pentru afisaj cu Anod-Comun Dim L(12) As Byte L(1) = &B01111001 L(2) = &B00100100 L(3) = &B00110000 L(4) = &B00011001 L(5) = &B00010010 L(6) = &B00000010 L(7) = &B01111000 L(8) = &B00000000 L(9) = &B00010000 L(10) = &B01000000 L(11) = &B00011100 'caracter Celsius L(12) = &B01000110 'Litera "C" Dim Multiplex As Byte Multiplex = 1 'Multiplexorul incepe cu 1 Dim Dotx As Byte Dotx = 0 Enable Interrupts '**********************[ Main Program ]***************************************** Start Adc Do If Button_min = 0 Then Gosub Setminute If Button_hr = 0 Then Gosub Sethour Loop End '--Rutina de reglaj minute Setminute: Lbl1: T = 0 Afisare = 0 Incr _min If _min > 59 Then _min = 0 Waitms 300 If Button_min = 0 Then Goto Lbl1 Return '--Rutina de reglaj ore Sethour: Lbl2: T = 0 Afisare = 0 Incr _hour If _hour > 23 Then _hour = 0 Waitms 300 If Button_hr = 0 Then Goto Lbl2 Return '*******************[ Timer0 Interrupt Routine ]******************************** Tmr0_isr: If Afisare = 0 Then Select Case Multiplex Case 1 : Cifra = _min Mod 10 'Minute Case 2 : Cifra = _min / 10 'Zeci de minute Case 4 : Cifra = _hour Mod 10 'Ore Case 8 : Cifra = _hour / 10 'Zeci de ore End Select Else Select Case Multiplex Case 1 : Cifra = 12 Case 2 : Cifra = 11 Case 4 : Cifra = Tem Mod 10 Case 8 : Cifra = Tem / 10 End Select End If If Cifra = 0 Then Cifra = 10 'afiseaza digitul 10 in loc de zero Digit = L(cifra) 'decodifica cifra pe digiti Portb = &B11110000 Or Multiplex 'adauga cuvantul Multiplex la PortB Portb = Not Portb 'inverseaza polaritatea pentru afisaj cu Anod-Comun If Multiplex = 4 Then 'selecteaza digitul 3 (2^2) If Afisare = 0 Then If Dotx = 0 Then Reset Portd.7 Else Set Portd.7 'clipeste ledul punct Else Set Portd.7 End If Else Set Portd.7 End If If Multiplex = 8 And _hour < 10 Then 'daca este aprinsa ultima cifra si ora>10... If Afisare = 0 Then Set Portb.3 'stinge digitul 4 daca afiseaza ora "00"sau temperatura End If If Multiplex < 8 Then 'limita maxima de multiplexare este 2^3=8 Shift Multiplex , Left , 1 'comuta la urmatorul digit Else Multiplex = 1 're-initializeaza multiplexarea de la primul digit 2^0 End If Return '********************[Rutina de takt ceas]********************************************************** Sectic: Incr T 'incrementeaza timerul de afisare If T > 5 Then 'limita timer de afisare 5sec T = 0 Toggle Afisare.0 'schimba bitul de selectie CEAS/TEMP End If Toggle Dotx.0 'clipesc punctele pe display If Afisare = 0 Then 'daca se afiseaza ceasul... Adc2 = Getadc(2) 'citeste intrarea de temperatura Temp = Adc2 / 2 'conversie pentru LM35 Tem = Temp End If Adcv = Getadc(4) Volt = Adcv / 2 'copiaza valoarea masurata Return[/code:1:1a06e7ac5b] [b:1a06e7ac5b][color=red:1a06e7ac5b](BASCOM-AVR version : 2.0.7.3 , Latest : 2.0.7.6 )[/b:1a06e7ac5b][/color:1a06e7ac5b]

Viewing all articles
Browse latest Browse all 20563

Trending Articles