Администрация форума не несёт ответственности за достоверность информации и оставляет за собой право редактировать или в особых случаях даже удалять посты без предупреждения. Спасибо за понимание.

Программирование ATMEL в BASCOM.

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Программирование ATMEL в BASCOM. » Вопросы - ответы » Динамическая индикация использовать любые порты


Динамическая индикация использовать любые порты

Сообщений 1 страница 4 из 4

1

Для отображения динамики нашел много подходов.
Черезь кеш.

Код:
'*********************************************[ ]*****************************************

$regfile = "m8adef.dat"                                     '  
$crystal = 8000000                                          '     

' Open "comb.0:9600,8,n,1" For Output As #1
'*****************************************[   ]************************************

Dim I(6) As Word                                            '  
Dim Count As Byte                                           '    
Dim Count_blink As Byte                                     '    
'***********************************************
Dim Sstr As String * 6
Dim Ind_str As String * 1
Dim K As Byte
Dim W As Bit
'===== I2C  scl  sda 
'===============================================================================
Config Sda = Portc.4                                        ' I2C Data
Config Scl = Portc.5                                        ' I2C Clock
   Config I2cdelay = 1                                      '    I2c   
   I2cinit
   Waitms 50
'=====       ds3231
Const Ds3231w = &HD0                                        '  
Const Ds3231r = &HD1                                        '  
'===========     DS3231
'===============================================================================
Declare Sub Ds3231
Dim Tds3231_bcd As Integer
Dim Temper_z As Byte At Tds3231_bcd + 1 Overlay             '     
Dim Temper_d As Byte At Tds3231_bcd + 0 Overlay             '  
Dim Tds3231 As Integer
Dim Tds3231_str As String * 5
'=====    DS3231
'===============================================================================
'=====  
Dim Seco As Byte
Dim Mine As Byte
Dim Hour As Word
Dim Day As Byte
Dim Dat As Byte
Dim Month As Byte
Dim Year As Byte
'===== - 
Dim Seco_bcd As Byte
Dim Mine_bcd As Byte
Dim Hour_bcd As Byte
Dim Day_bcd As Byte
Dim Dat_bcd As Byte
Dim Month_bcd As Byte
Dim Year_bcd As Byte
'=====  
Dim Secostr As String * 2
Dim Minestr As String * 2
Dim Hourstr As String * 2
' 1  1820
'============================================================================================================
Dim Tds1 As Integer                                         '   1   0.1. 10 = 1,0 
Dim Tds1_str As String * 4
Dim Err_c1 As Bit                                           ' 
' 2  1820
'============================================================================================================
Dim Tds2 As Integer                                         '   1   0.1. 10 = 1,0 
Dim Tds2_str As String * 4
Dim Err_c2 As Bit                                           ' 
'***********************************************[ ]*******************************************

Ddrb = &B00111111                                           '   (), 2  ()
Portb = &B00111111                                          '  ,    

'-------------------------

Ddrd = &B00111111                                           '   ()
Portd = &B00000000                                          '  

'*********************************************[ ]*****************************************
Const Ds1820 = 100
Config Timer0 = Timer , Prescale = 64                       '   (~250 )
On Timer0 Refresh                                           '  

Config Timer1 = Timer , Prescale = 8
On Timer1 Pulse

Enable Interrupts                                           '   
Enable Timer0                                               '      ()
Enable Timer1
Start Timer1
Declare Sub Look_timer()
'********************************************[  ]****************************************

Dig1 Alias Portb.0 : Dig2 Alias Portb.1 : Dig3 Alias Portb.2 : Dig4 Alias Portb.3 : Dig5 Alias Portb.4 : Dig6 Alias Portb.5 : Dot Alias Portd.0
A Alias Portd.1 : B Alias Portd.2 : C Alias Portd.3 : D Alias Portd.4 : E Alias Portd.5

'*********************************************[  ]****************************************
Do                                                          '  
 Gosub Ds3231
 Gosub Temper
 Gosub Ind                                                  '     
 Waitms 500
 Loop
'***************************************************************************************************************
Pulse:
   Incr K
Return
'***********************************[    ]*******************************
Refresh:                                                    '   0 (  ~4 )

 Set Dig1 : Set Dig2 : Set Dig3 : Set Dig4 : Set Dig5 : Set Dig6 : Reset Dot       '  

 Incr Count : If Count > 6 Then Count = 1                   '     
 Incr Count_blink : If Count_blink > 250 Then Count_blink = 1       '   

    Ind_str = Mid(sstr , Count , 1)
  Select Case Ind_str
    Case "0" : D = 0 : C = 0 : B = 0 : A = 0                '&b0000
    Case "1" : D = 0 : C = 0 : B = 0 : A = 1                '&b0001
    Case "2" : D = 0 : C = 0 : B = 1 : A = 0                '&b0010
    Case "3" : D = 0 : C = 0 : B = 1 : A = 1                '&b0011
    Case "4" : D = 0 : C = 1 : B = 0 : A = 0                '&b0100
    Case "5" : D = 0 : C = 1 : B = 0 : A = 1                '&b0101
    Case "6" : D = 0 : C = 1 : B = 1 : A = 0                '&b0110
    Case "7" : D = 0 : C = 1 : B = 1 : A = 1                '&b0111
    Case "8" : D = 1 : C = 0 : B = 0 : A = 0                '&b1000
    Case "9" : D = 1 : C = 0 : B = 0 : A = 1                '&b1001
    Case " " : D = 1 : C = 1 : B = 1 : A = 1                '&b1111 
  End Select

 If W = 1 And Count_blink < 125 Then                        '     
   If Count = 2 Or Count = 4 Then Set Dot
 End If

 If W = 0 Then
    If Count = 2 Or Count = 5 Then Set Dot
 End If

  Select Case Count                                         '     
    Case 1 : Reset Dig1
    Case 2 : Reset Dig2
    Case 3 : Reset Dig3
    Case 4 : Reset Dig4
    Case 5 : Reset Dig5
    Case 6 : Reset Dig6
  End Select

 Return
'----------------------------------------------------------------------------------------------------------------

Ind:
   If K < 30 Then
   Sstr = Hourstr + Minestr + Secostr
    W = 1
   End If

   If Left(tds1_str , 1) = "-" Then
     E = 1
     Else
     E = 0
   End If

   Tds1_str = Mid(tds1_str , 2 , 3)
   Tds2_str = Mid(tds2_str , 2 , 3)
   If K => 30 And K < 40 Then
'    Sstr = Tds1_str + Tds2_str
    Sstr = Tds1_str + Tds3231_str
    W = 0
   End If

'   If K => 40 Then
'    Sstr = Tds2_str + "   "
'    Sstr = Tds3231_str + "   "
'    W = 0
'   End If

  If K > 40 Then K = 0
Return
'*****************************************************[]***************************************************
'   DS18B20
'====================================================================================================
Temper:
   Gosub Look_timer
   1wreset Pinc , 0
   Gosub Look_timer
   If Err = 1 Then
         Err_c1 = 1                                         '   
         Tds1 = 32767                                       '       
      Else
         Err_c1 = 0
         1wwrite &HCC , 1 , Pinc , 0                        ' ROM( )
         1wwrite &H44 , 2 , Pinc , 0                        ' ( )
   End If

'     Waitms 94

   If Err_c1 = 0 Then
      Gosub Look_timer                                      '     
      1wreset Pinc , 0
      Gosub Look_timer
      If Err = 1 Then
            Tds1 = 32767                                    '       
          Else                                              ',    ,   
            1wwrite &HCC , 1 , Pinc , 0
            1wwrite &HBE , 1 , Pinc , 0
            Tds1 = 1wread(2 , Pinc , 0)
            Tds1 = Tds1 * 10
            Tds1 = Tds1 \ 16
      End If
       Tds1_str = Str(tds1)
       Tds1_str = Format(tds1_str , "+000")
      Else
       Tds1 = 32767
       Tds1_str = " 000"
   End If
'===================================================================
   Gosub Look_timer
   1wreset Pinc , 1
   Gosub Look_timer
   If Err = 1 Then
         Err_c2 = 1                                         '   
         Tds2 = 32767                                       '       
      Else
         Err_c2 = 0
         1wwrite &HCC , 1 , Pinc , 1                        ' ROM( )
         1wwrite &H44 , 2 , Pinc , 1                        ' ( )
   End If

'      Waitms 94                                           '   9  

   If Err_c2 = 0 Then
      Gosub Look_timer                                      '     
      1wreset Pinc , 1
      Gosub Look_timer
      If Err = 1 Then
            Tds2 = 32767                                    '       
          Else                                              ',    ,   
            1wwrite &HCC , 1 , Pinc , 1
            1wwrite &HBE , 1 , Pinc , 1
            Tds2 = 1wread(2 , Pinc , 1)
            Tds2 = Tds2 * 10
            Tds2 = Tds2 \ 16
      End If
       Tds2_str = Str(tds2)
       Tds2_str = Format(tds2_str , "+000")
      Else
       Tds2 = 32767
       Tds2_str = " 000"
   End If

Return
'=====  DS3231
'===============================================================================
Ds3231:

   I2cstart
   I2cwbyte Ds3231w
   I2cwbyte &H00                                            ' 
   I2cstart
   I2cwbyte Ds3231r
'=====   
   I2crbyte Seco_bcd , Ack
   I2crbyte Mine_bcd , Ack
   I2crbyte Hour_bcd , Ack
   I2crbyte Day_bcd , Ack
   I2crbyte Dat_bcd , Ack
   I2crbyte Month_bcd , Ack
   I2crbyte Year_bcd , Nack
   I2cstop

   I2cstart                                                 '    
   I2cwbyte Ds3231w                                         '  
   I2cwbyte &H11                                            '     
   I2cstart                                                 '      
   I2cwbyte Ds3231r                                         '      
   I2crbyte Temper_z , Ack                                  '     
   I2crbyte Temper_d , Nack                                 '  
   I2cstop                                                  ' 
   Gosub Convert

Return

'=====      
'===============================================================================
Convert:
'=====   
   Seco = Makedec(seco_bcd)
   Mine = Makedec(mine_bcd)
   Hour = Makedec(hour_bcd)
   Day = Makedec(day_bcd)
   Dat = Makedec(dat_bcd)
   Month = Makedec(month_bcd)
   Year = Makedec(year_bcd)

   If Temper_z < 128 Then
         Select Case Temper_d
            Case 0 : Temper_d = 0                           '0000_0000
            Case 64 : Temper_d = 2                          '0100_0000
            Case 128 : Temper_d = 5                         '1000_0000
            Case 192 : Temper_d = 7                         '1100_0000
         End Select
         Tds3231 = Temper_z * 10
         Tds3231 = Tds3231 + Temper_d
      Else
         Temper_z = Not Temper_z
         Temper_d = Not Temper_d
         Select Case Temper_d
            Case 0 : Temper_d = 0                           '1111_1111
            Case 63 : Temper_d = 2                          '0011_1111
            Case 127 : Temper_d = 5                         '0111_1111
            Case 191 : Temper_d = 7                         '1011_1111
         End Select
         Tds3231 = Temper_z * 10
         Tds3231 = Tds3231 + Temper_d
         Tds3231 = Tds3231 * -1
   End If
'=====
   Secostr = Str(seco)
   Secostr = Format(secostr , "00")
   Minestr = Str(mine)
   Minestr = Format(minestr , "00")
   Hourstr = Str(hour)
   Hourstr = Format(hourstr , "00")
   Tds3231_str = Str(tds3231)
   Tds3231_str = Format(tds3231_str , "000")
   Return
'===============================================================================
Look_timer:
    Do
      nop
    Loop Until Tcnt0 < Ds1820
 Return

+1

2

Через CASE работает нормально.
Это "табличные редакторы"
Хочу прописать через массив. Но использовать любые свободные порты, а через Overlay.

Код:
Dim Indikator As Byte
Dim Pa As Byte At Indikator + 0 Overlay                     ' 0
Dim Pb As Byte At Indikator + 1 Overlay                     ' 1
Dim Pc As Byte At Indikator + 2 Overlay                     ' 2
Dim Pd As Byte At Indikator + 3 Overlay                     ' 3
Код:
'***********************************[    ]*******************************
Refresh:                                                    '   0 (  ~4 )

 Set Dig1 : Set Dig2 : Set Dig3 : Set Dig4 : Set Dig5 : Set Dig6 : Reset Dot       '  

 Incr Count : If Count > 6 Then Count = 1                   '     
 Incr Count_blink : If Count_blink > 250 Then Count_blink = 1       '   

    Ind_str = Mid(sstr , Count , 1)
    I = Val(ind_str)
    If Ind_str = " " Then I = 10

    Indikator = Lookup(i , Digits)
    A = Pa : B = Pb : C = Pc : D = Pd

 If W = 1 And Count_blink < 125 Then                        '     
   If Count = 2 Or Count = 4 Then Set Dot
 End If

 If W = 0 Then
    If Count = 2 Or Count = 5 Then Set Dot
 End If

  Select Case Count                                         '     
    Case 1 : Reset Dig1
    Case 2 : Reset Dig2
    Case 3 : Reset Dig3
    Case 4 : Reset Dig4
    Case 5 : Reset Dig5
    Case 6 : Reset Dig6
  End Select

 Return
'***************************************************************************************************************
Digits:                                                     ' 
 Data 0                                                     '0
 Data 1                                                     '1
 Data 2                                                     '2
 Data 3                                                     '3
 Data 4                                                     '4
 Data 5                                                     '5
 Data 6                                                     '6
 Data 7                                                     '7
 Data 8                                                     '8
 Data 9                                                     '9
 Data 15                                                    '" "
'***************************************************************************************************************


Исправлены все орфографические ошибки.

+1

3

Когда наши Модераторы начнут пинать за правильное написание если уж не терминов, то уж хотя бы обычных обиходных слов ?
"ЧерезЬ" - просто режет глаза...  :dontknow:

0

4

Ошибся, извиняюсь. Overlay все равно в прерывании не работает. С массивом ни чего не получается.

0


Вы здесь » Программирование ATMEL в BASCOM. » Вопросы - ответы » Динамическая индикация использовать любые порты