FAQ | Points | Add... | Recent posts | Search | Register | Log in


[atmega8][bascom]Wyswietlacz 7 segmentowy


Post new topic  Reply to topic      Main Page -> Forum Index -> Microcontrollers Generally -> AVR Microcontrollers -> [atmega8][bascom]Wyswietlacz 7 segmentowy
Author
Message
Macias871
Poziom 12
Poziom 12


Joined: 18 Feb 2004
Posts: 82

Post#1 Post from the author of the topic 17 Sep 2008 19:39   

[atmega8][bascom]Wyswietlacz 7 segmentowy


Może ma ktos z was gotowy program do wyswietlania cyfr na dwóch wyswietlaczach? Może w przerwaniu. Mam cos takiego ale wyswietlacz mruga.

Moderated by McRancor:
Używaj znaczników "code" jak wklejasz kod. Poprawiłem


Code:

                    $regfile = "m8def.dat"
$crystal = 8000000


   Config Portd = Output
   Config Pinb.0 = Output
   Config Pinb.1 = Output
   Config Pinb.2 = Output
   Config Pinb.3 = Output
   Config Pinb.4 = Input
   Config Pinb.5 = Input
   Config Pinb.6 = Input
   Config Pinb.7 = Input
   Config Portc = Output

   Set Pinb.5
   Set Pinb.6
   Set Pinb.7


      Dim A As Integer , Licznik As Byte , T As Integer ,
      Dim Setki As Byte , Dziesiatki As Byte , Jednostki As Byte ,
      Dim Mux As Byte ,

   Swstart Alias Pinb.5
   Swstop Alias Pinb.6
   Funk Alias Pinb.7

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Compare B Pwm = Disconnect , Prescale = 64
Dim Wart_ac As Word


Dim P As Byte                                               'pozycja                                               'x temperatura
Dim X As Single                                             'temperatura z czujnika
Dim Z As Byte                                               'czas przedmuchu
Dim J As Byte                                               'czas pomiedzy przedmuch
Dim I As Byte                                               'obr min
Dim S As Single                                             'temperatura w pamieci
Dim U As Byte

   Config Timer0 = Timer , Prescale = 64
   Enable Interrupts
   Enable Timer0
   On Timer0 Co4ms

Dmuchawa Alias Pinb.2
Pompa Alias Pinb.3
Cz_temp Alias Pinb.4

Declare Sub Temp
Declare Sub Przedmuch
Declare Sub Czas_m_przedmuch
Declare Sub Obr_min
Declare Sub Obr_max
Declare Sub Temperatura
Declare Sub Pompa
Declare Sub Dmuchawa_sub
Declare Sub Praca
Declare Sub Wyswietl

Declare Sub Obroty_max_sub
Declare Sub Obroty_min_sub                                  'end program



P = 1
Do

If Funk = 0 Then
Waitms 200
Incr P
End If
   If P = 5 Then
   P = 0
End If




If P = 0 Then
Portc = &B11111110
Waitms 100
If Swstart = 0 Then
Gosub Praca
End If
End If
If P = 1 Then
Portc = &B11111101
Gosub Temp
End If
If P = 2 Then
Portc = &B11111011
Gosub Przedmuch
End If
If P = 3 Then
Gosub Czas_m_przedmuch
Portc = &B11110111
End If
If P = 4 Then
Gosub Obr_min
Portc = &B11101111
End If
If P = 5 Then
Gosub Obr_max
Portc = &B11011111
End If
Loop




Sub Temp
Readeeprom X , 1

If Swstart = 0 Then
 Waitms 10
If Swstart = 0 Then
 Incr X
 T = X
 Waitms 20


If X = 91 Then X = 35
End If
End If
If Swstop = 0 Then
 Waitms 10
If Swstop = 0 Then
 Decr X
 T = X
 Waitms 20


If X = 35 Then X = 90
End If
End If
Writeeeprom X , 1
End Sub

Sub Przedmuch
If Swstart = 0 Then
 Waitms 50
If Swstart = 0 Then
 Incr Z
If Z = 25 Then Z = 1
End If
End If
If Swstop = 0 Then
 Waitms 50
If Swstop = 0 Then
 Decr Z
If Z = 0 Then Z = 25
End If
End If
Writeeeprom Z , 2
End Sub

Sub Czas_m_przedmuch
If Swstart = 0 Then
 Waitms 50
If Swstart = 0 Then
 Incr J
If J = 99 Then J = 1
End If
End If
If Swstop = 0 Then
 Waitms 50
If Swstop = 0 Then
 Decr J
If J = 0 Then J = 99
End If
End If
Writeeeprom J , 3
End Sub

Sub Obr_min
If Swstart = 0 Then
 Waitms 50
If Swstart = 0 Then
 Incr I
If I = 12 Then I = 1
End If
End If
If Swstop = 0 Then
 Waitms 50
If Swstop = 0 Then
 Decr I
If I = 1 Then I = 11
End If
End If
Writeeeprom I , 4
End Sub

Sub Obr_max
If Swstart = 0 Then
 Waitms 50
If Swstart = 0 Then
 Incr U
If U = 11 Then U = 1
End If
End If
If Swstop = 0 Then
 Waitms 50
If Swstop = 0 Then
 Decr U
If U = 1 Then U = 11
End If
End If
Writeeeprom U , 5
End Sub

Sub Temperatura
Start Adc

Wart_ac = Getadc(3)
S = Wart_ac / 10
End Sub

Sub Praca
Do
Gosub Temperatura
If S < X Then
Gosub Obroty_max_sub
Set Pompa
End If
If S > X Then
Gosub Obroty_min_sub
End If
If S > 90 Then
Pwm1a = 1
End If

Loop
End Sub

Sub Obroty_max_sub
Readeeprom U , 5
Pwm1a = U * 93
End Sub

Sub Obroty_min_sub
Readeeprom I , 4
Pwm1a = I * 93
End Sub








                                                      'end program                                                      'end program


   Co4ms:
   'Standardowa konwersja binarna 0...255 na trzycyfrową BCD
  A = T
      If A > 100 Then
          Setki = 1
          A = A - 100
       Else
          Setki = 10
       End If




    A = Makebcd(a)
    Jednostki = A And 15
    Dziesiatki = A
    Shift Dziesiatki , Right , 4
    'Standardowa obsługa wyświetlaczy
    Incr Mux
    If Mux = 3 Then Mux = 0
    Portb = 127
    Select Case Mux
    Case 0
      Portd = Lookup(jednostki , Tabela)
      Portb.1 = 0
    Case 1
      Portd = Lookup(dziesiatki , Tabela)
      Portb.0 = 0

    End Select
   Return



 Tabela:
Data &B00111111 , &B00000110 , &B01011011 , &B01001111 , &B01100110,
Data &B01101101 , &B01111101 , &B00000111 , &B01111111 , &B01101111

Back to top
   
Google

Google Adsense


Post# Post from the author of the topic 17 Sep 2008 19:39   





Back to top
   
ZbeeGin
Poziom 23
Poziom 23


Joined: 22 Apr 2002
Posts: 2625
Location: 50°19'N 18°55'E

Post#2 17 Sep 2008 19:42   

Re: [atmega8][bascom]Wyswietlacz 7 segmentowy


Mruga gdyż pewnie nie przestawiłeś oscylatora, zatem procesor nie jest taktowany 8MHz tylko 1MHz.
Back to top
   
Google

Google Adsense


Post# 17 Sep 2008 19:42   





Back to top
   
Macias871
Poziom 12
Poziom 12


Joined: 18 Feb 2004
Posts: 82

Post#3 Post from the author of the topic 17 Sep 2008 20:35   

Re: [atmega8][bascom]Wyswietlacz 7 segmentowy


W fuse bitach mam ustawione na 8 mhz. Pierwsza cyfre wyswietla slabo a na drugiej niewiadomo co jest!
Back to top
   
Google

Google Adsense


Post# Post from the author of the topic 17 Sep 2008 20:35   





Back to top
   
dawid512
Poziom 21
Poziom 21


Joined: 15 Nov 2005
Posts: 1430
Location: Krościenko Wyżne

Post#4 17 Sep 2008 23:39helpful post - solution   

Re: [atmega8][bascom]Wyswietlacz 7 segmentowy


Pokaż schemat to raz.
Dwa:

co to jest?
Code:
Set Pinb.5
Set Pinb.6
Set Pinb.7


Tak po za tym chyba brakuje ci wartości początkowej timera0...
Nie obraź się ale przy tym oscylatorze i preskalerze 64 otrzymasz przerwanie co najwyżej co 2ms...

Na koniec zapamiętaj że program zawsze umieszcza się w znacznikach "code".
Back to top
   
cepelia
Poziom 11
Poziom 11


Joined: 03 Jun 2007
Posts: 67
Location: czestochowa

Post#5 18 Sep 2008 07:58   

Re: [atmega8][bascom]Wyswietlacz 7 segmentowy


Nie wiem jak koledzy ale ja zawsze jak mam narysować coś na ledach to robię to tak.
Code:


tu oczywiście deklaruje zmienne
i configoruje timer

Do

  ' display DS1
  Reset Ds4 : Reset Ds3 : Reset Ds2 : Set Ds1
  Led7 = Lookup(zmienna_a , Led7s_table)
  Waitms Ms
  ' display DS2
  Reset Ds4 : Reset Ds3 : Set Ds2 : Reset Ds1
  Led7 = Lookup(zmienna_b , Led7s_table)
  Waitms Ms

Loop

przerwanie:

a tu umieszczam cały program co ma się wyświetlić

no i oczywiście tabelka ze znakami



i to zasadniczo sprawdza się zawsze nawet jak jest wyświetlacz z więcej niż 2 kostek. Ważne co by nic więcej nie dawać do pętli do-loop, a jeszcze jedno sprawdź czy nie masz włączonego wathdoga bo to jest domyślne ustawienie w kalkulatorze do fusbitów.
Back to top
   
Google

Google Adsense


Post# 18 Sep 2008 07:58   





Back to top
   
Macias871
Poziom 12
Poziom 12


Joined: 18 Feb 2004
Posts: 82

Post#6 Post from the author of the topic 18 Sep 2008 18:32   

Re: [atmega8][bascom]Wyswietlacz 7 segmentowy


Set pinb.5 .. to podciaganie pinów do zasilania, w dalszej czesci progrmu piny te sa uzywane do sprawdzania stanu na przyciskach. Calosc mam zmontowana na zestawie zl2avr a ogolnie to jest progrma do oryginalnego sterownika pieca mialowego. W tamtym uszkodzil sie procesor i probuje napisac program do niego. Napisalem kawalek od nowa i juz lepiej. Chodzi o taki sterownik : http://www.foster-pleszew.com.pl/index.php?go=oferta&cat=msrt&pid=02

a oto nowy kawalek programu.

Code:

$regfile = "m8def.dat"
$crystal = 8000000

   Config Portd = Output
   Config Pinb.0 = Output
   Config Pinb.1 = Output
   Config Pinb.2 = Output
   Config Pinb.3 = Output
   Config Pinb.4 = Input
   Config Pinb.5 = Input
   Config Pinb.6 = Input
   Config Pinb.7 = Input
   Config Portc = Output

   Set Pinb.5
   Set Pinb.6
   Set Pinb.7

   Swstart Alias Pinb.5
   Swstop Alias Pinb.6
   Funk Alias Pinb.7

   Config Timer0 = Timer , Prescale = 256
   Enable Interrupts
   Enable Timer0
   On Timer0 Co4ms

      Dim Odczyt(2)as Byte , A As Integer , Licznik As Byte , T As Integer ,
      Dim Setki As Byte , Dziesiatki As Byte , Jednostki As Byte ,
      Dim Mux As Byte



Dim P As Byte                                               'pozycja                                               'x temperatura
Dim X As Single                                             'temperatura z czujnika
Dim Z As Byte                                               'czas przedmuchu
Dim J As Byte                                               'czas pomiedzy przedmuch
Dim I As Byte                                               'obr min
Dim S As Single                                             'temperatura w pamieci
Dim U As Byte



  Declare Sub Praca
  Declare Sub Temp
  Declare Sub Funkcje
Portc = &B111111110
Readeeprom X , 1
Do
If Funk = 0 Then
Waitms 200
Incr P
If P = 5 Then
P = 0
End If

End If

If P = 0 Then
Portc = &B11111110
Waitms 10
If Swstart = 0 Then
Gosub Praca
End If
End If


If P = 1 Then
Portc = &B11111101

T = X
Gosub Temp
End If

If P = 2 Then
Portc = &B11111011
End If

If P = 3 Then
Portc = &B11110111
End If

If P = 4 Then
Portc = &B11101111
End If

If P = 5 Then
Portc = &B11011111
End If
Loop



Sub Temp



If Swstart = 0 Then


Incr X
Waitms 50
T = X
Waitms 50

End If
If X = 91 Then
X = 35
End If


If Swstop = 0 Then

Decr X
Waitms 50
T = X
Waitms 50
If X < 35 Then
 X = 90
End If
End If
If Funk = 0 Then
Writeeeprom X , 1
Waitms 10
Incr P
End If


End Sub




Sub Praca
Do
Portc = &B00011000
Waitms 100
Portc = &B00101010
Waitms 100
Loop Until Funk = 0

End Sub







   End                                                      'end program                                                      'end program


   Co4ms:
   'Standardowa konwersja binarna 0...255 na trzycyfrową BCD
   A = T
      If A > 100 Then
          Setki = 1
          A = A - 100
       Else
          Setki = 10
       End If




    A = Makebcd(a)
    Jednostki = A And 15
    Dziesiatki = A
    Shift Dziesiatki , Right , 4
    'Standardowa obsługa wyświetlaczy
    Incr Mux
    If Mux = 2 Then Mux = 0
    Portb.0 = 1
    Portb.1 = 1
    Select Case Mux
    Case 0
      Portd = Lookup(jednostki , Tabela)
      Portb.1 = 0
    Case 1
      Portd = Lookup(dziesiatki , Tabela)
      Portb.0 = 0

    End Select
   Return

 Tabela:
Data &B00111111 , &B00000110 , &B01011011 , &B01001111 , &B01100110,
Data &B01101101 , &B01111101 , &B00000111 , &B01111111 , &B01101111

Back to top
   
Post new topic  Reply to topic      Main Page -> Forum Index -> Microcontrollers Generally -> AVR Microcontrollers -> [atmega8][bascom]Wyswietlacz 7 segmentowy
Page 1 of 1
Similar topics
Wyswietlacz segmentowy a podłączenie do uC (36)
Wyswietlacz 8 segmentowy + AVR (11)
[atmega8][Bascom] plus wyswietlacz z siemensa C60 (3)
[atmega8][bascom avr] pcf8583,wyswietlacz siedmiosegmentowy (9)
BASCOM + wyswietlacz nokia 3310 + Atmega8 (7)
atmega8 i wyświetlacz 7 segmentowy LED ==> BASCOM (31)
Bascom 7 segmentowy wyswietlacz (3)
[ATmega8][Bascom] Wyswietlacz 7 segmentowy LED. (19)
Wyswietlacz LED 4 segmentowy CSK584H (2)
Wyswietlacz 7 segmentowy - problem logiczny :/ (6)

Page generation time: 0.19 seconds


FAQ || Administrator || Moderators || Widgets and banners || Contact
elektroda.pl topic RSS feed