↑ ↓

Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

Anlamadığım Bir Şey Var

Başlatan agora_meyhanesi42, 05 Ağustos 2008, 10:07:42

agora_meyhanesi42

Evet anlamadığım bir şey var. Kaç gündür 4 adet 7 segment display ile bir saat ve termometre yapmaya calışıyorum. ds18b20 ıs sensorum mevcut bununla ilgili onlarca devre şeması denemedim yapılmış hex kodlarını pic 16 f 84a ya yukledim fakat ne yaptıysam olmadı devrelerimi en on defa kontrol ediyorum fakat hiç bir yanlışlık yok. Buldugum hex kodlarının kaynak kodları olmadıgı için programda hata olup olmadıgını bulamıyorum. Programı kendim yazayım diyorum onunda içinden cıkamıyorum :)
Lütfen Yardım Lütfen Yardım.

Bide buraya resim nasıl upload ediliyor bir turlu bulamadım bulsam devre semasını atacagım :)
Yüksel Türk ! Senin için yükselmenin hududu yoktur...

ilker_32

Bilmediğin devreyi yapmana gerek yok.

http://imageshack.us/

Resimi buradan upload edebilirsiniz.

agora_meyhanesi42

sagol cok yardımcı oldugun için ;)
Yüksel Türk ! Senin için yükselmenin hududu yoktur...

turkplc

'Proton
device 16F628
xtal=4
dim i as byte,j as byte, k as byte
dim A as byte,cnt as byte,cnt1 as byte,cnt2 as byte
Dim A0 As Byte , A1 As Byte , A2 As Byte , A3 As Byte , A4 As Byte
dim timer0_Enable as bit ,timer1_Enable as bit ,timer2_Enable as bit ,err as bit
DIM BUTONNO AS BYTE
Dim command as     byte            ' Storage for command
Dim temp    as     word            ' Storage for temperature
		
Symbol DQ      =     PORTa.2         ' Alias DS1820 data pin
Symbol DQ_DIR  =     TRISa.2         ' Alias DS1820 data direction pin

Symbol Buton1 = PORTb.1         ' Alias DS1820 data pin
Symbol Buton2 = PORTb.3         ' Alias DS1820 data direction pin

'Config $0378
DECLARE LCD_DTPIN PORTB.4
DECLARE LCD_ENPIN PORTb.0
DECLARE LCD_RSPIN PORTb.1
DECLARE LCD_INTERFACE 4 
DECLARE LCD_LINES 2

        HSERIAL_BAUD = 9600		' Set baud rate to 9600
        HSERIAL_RCSTA = %10010000       ' Enable serial port and continuous receive
        HSERIAL_TXSTA = %00100100       ' Enable transmit and asynchronous mode 
        HSERIAL_CLEAR = ON		' Enable Error clearing on received characters
DECLARE SDA_PIN PORTa.0
DECLARE SCL_PIN PORTa.1
'DECLARE SLOW_BUS ON
'DECLARE BUS_SCL ON  
symbol clockout=%11010000	'set the 1307 to receive data 
symbol clockin=%11010001	'set the 1307 to transmit data 
Dim Secs As Byte 
Dim Mins As Byte 
Dim Hrs As Byte 
Dim day As Byte 
Dim Date As Byte 
Dim Month As Byte 
Dim Year As Byte 
Dim Ctrl As Byte
Dim Temp1 As Byte
Dim Temp2 As Byte
Dim TempVal As Byte 

 
 

ON_INTERRUPT Goto Timer_Interrupt

Main:
OPTION_REG = $84       ' assign prescaler to TMR0
option_reg.7=0            
TMR0   =  96
INTCON = $A0           ' enable TMRO interrupt
CMCON=7
TrisA=255
TrisB.1=1:TrisB.3=1
cnt = 0
cnt1 = 0
'===============================================
    Busout 11010000, 7, [$10]
    'busout clockout,0,[0]
    'gosub init
    delayms 100
    
    gosub InitTemp
    gosub read_DS1307
    GOSUB SEND_AT
    'Ctrl=0
    'GOSUB write_DS1307
    timer1_Enable=1
Basla:
    IF BUTON1=1 AND BUTON2=1 THEN
    a4=2:BUTONNO=0
    gosub read_DS1307
    GOSUB SEND_AT
    GOTO PROGRAMLAMA
    ENDIF
    
    if timer0_Enable = 1 then
        'timer0_Enable = 0
        'gosub read_DS1307
        'inc cnt1
        'if cnt1>9 then
        '    if cnt1>12 then cnt1=0
        'gosub ReadTemp
        'gosub InitTemp
        'endif
        'GOSUB SEND_AT
        'a4=~A4
    endif

    if timer0_Enable = 1 then
        timer0_Enable = 0
        
        if timer2_Enable=1 then inc cnt2
        if cnt2>5 then
        cnt1=0:timer1_Enable=1
        cnt2=0:timer2_Enable=0
        a4=1
        gosub read_DS1307
        GOSUB SEND_AT
        endif 
               
        if timer1_Enable=1 then inc cnt1
        if cnt1>10 then
        cnt1=0:timer1_Enable=0
        cnt2=0:timer2_Enable=1
        a4=0
        gosub ReadTemp
        GOSUB SEND_AT
        gosub InitTemp
        endif

    endif
    
    
goto basla

Init: 'enable the DS1307's crystal oscillator
Bstart ' Send a START condition
Busout %11010000 ' Send slave address and Write command
Busout 0 ' Point to register 0 (Seconds)
Busout 0 ' Clear the register's contents 
Bstop ' Send a STOP condition
return

PROGRAMLAMA:
    if timer0_Enable = 1 then
        timer0_Enable = 0
        IF BUTON1=0 AND BUTON2=1 THEN
            IF BUTONNO=2 THEN
            GOSUB write_DS1307
            goto basla
            ENDIF
        BUTONNO=1
        INC MINS
        IF MINS >59 THEN MINS=0
        GOSUB DIGITAYARLA
        GOSUB SEND_AT
        ENDIF
        IF BUTON1=1 AND BUTON2=0 THEN
            IF BUTONNO=1 THEN
            GOSUB write_DS1307
            goto basla
            ENDIF
        BUTONNO=2
        INC HRS
        IF HRS >23 THEN HRS=0
        GOSUB DIGITAYARLA
        GOSUB SEND_AT
        ENDIF
    ENDIF
GOTO PROGRAMLAMA

SEND_AT:
    HRSOUT 13
    'delayus 30
    HRSOUT A0,a1,a2,a3,a4
    'HRSOUT A0
    'HRSOUT A1
    'HRSOUT A2
    'HRSOUT A3
    'HRSOUT A4
RETURN

Timer_Interrupt:
   cnt = cnt + 1         ' increment value of cnt on every interrupt
   TMR0   = 96
   if cnt = 200 then ' if cnt is 200, then toggle portb leds and reset cnt
   cnt = 0
   timer0_Enable = 1
   endif
   INTCON = $20          ' set T0IE, claer T0IF
Context Restore
RETURN



InitTemp:
        Gosub init1820          ' Init the DS1820
        'if err=1 then
        'err=0
        'goto InitTemp
        'endif
        
        command = $cc           ' Issue Skip ROM command
        Gosub write1820

        command = $44           ' Start temperature conversion
        Gosub write1820
return
ReadTemp:
        'Delayms 2000              ' Wait 2 seconds for conversion to complete
        Gosub init1820          ' Do another init
        command = $cc           ' Issue Skip ROM command
        Gosub write1820
        command = $be           ' Read the temperature
        Gosub write1820
        Gosub read1820
        'Print $fe, 1, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
        'temp = temp >> 1
        'HRSOUT dec temp
        if temp<32767 then
        temp=temp/16
        a0=temp/10
        a1=temp//10
        a2=16
        a3=12
        else
        temp=65536 - temp
        temp=temp/16
        a0=17
        a1=temp/10
        a2=temp//10
        a3=16
        endif
        a4=0
return
init1820:
        Low DQ                  ' Set the data pin low to init
        Delayus 500             ' Wait > 480us
        DQ_DIR = 1              ' Release data pin (set to input for high)

        Delayus 100             ' Wait > 60us
        If DQ = 1 Then
                'Print $fe, 1, "DS1820 not present"
                'Delayms 500
                err=1
        Endif
        Delayus 400             ' Wait for end of presence pulse
        Return
write1820:
        For i = 1 to 8          ' 8 bits to a byte
                If command.0 = 0 Then
                        Gosub write0    ' Write a 0 bit
                Else
                        Gosub write1    ' Write a 1 bit
                Endif
                command = command >> 1  ' Shift to next bit
        Next i
        Return
write0:
        Low DQ
        Delayus 60              ' Low for > 60us for 0
        DQ_DIR = 1              ' Release data pin (set to input for high)
        Return
write1:
        Low DQ                  ' Low for < 15us for 1
@       nop                     ' Delay 1us at 4MHz
        DQ_DIR = 1              ' Release data pin (set to input for high)
        Delayus 60              ' Use up rest of time slot
        Return
read1820:
        For i = 1 to 16         ' 16 bits to a word
                temp = temp >> 1        ' Shift down bits
                Gosub readbit   ' Get the bit to the top of temp
        Next i
        Return
readbit:
        temp.15 = 1             ' Preset read bit to 1
        Low DQ                  ' Start the time slot
@       nop                     ' Delay 1us at 4MHz
        DQ_DIR = 1              ' Release data pin (set to input for high)
        If DQ = 0 Then
                temp.15 = 0     ' Set bit to 0
        Endif
        Delayus 60              ' Wait out rest of time slot
        Return
        
 read_DS1307:
    BStart
    BusIn 11010001, 0, [Secs, Mins, Hrs, day, Date, Month, Year, Ctrl]
    BStop
    TempVal=Secs
    GoSub BCD_TO_BIN
    Secs=TempVal
    TempVal=Mins
    GoSub BCD_TO_BIN
    Mins=TempVal
    TempVal=Hrs
    GoSub BCD_TO_BIN
    Hrs=TempVal
    GOSUB DIGITAYARLA
return
DIGITAYARLA:
    a0=Hrs/10
    a1=Hrs//10
    a2=Mins/10
    a3=Mins//10
RETURN
write_DS1307:
    TempVal=Secs
    GoSub BIN_TO_BCD
    Secs=TempVal
    TempVal=Mins
    GoSub BIN_TO_BCD
    Mins=TempVal
    TempVal=Hrs
    GoSub BIN_TO_BCD
    Hrs=TempVal
    BStart
    Busout 11010000, 0, [Secs, Mins, Hrs, day, Date, Month, Year] 'Write initial values for time / Date 
    BStop
return
BCD_TO_BIN:                                    ' Convert the BCD values into BIN
     Temp1 = $0F & TempVal                     ' Clear off the top four bits 
     Temp1 = DIG Temp1, 0
     Temp2 = TempVal >> 4                       ' Shift down four to read 2 BCD value
     Temp2 = DIG Temp2, 0
     TempVal = Temp2 * 10 + Temp1
Return
BIN_TO_BCD:
     Temp1 = Dig TempVal, 0                     ' GET THE DEC DIGIT FOR THE FIRST NIBBLE
     Temp2 = Dig TempVal, 1                     ' GET THE DEC DIGIT FOR THE FIRST NIBBLE
     Temp2 = Temp2 << 4                          ' MOVE NUMBER OVER TO 2ND NIBBLE
     TempVal = Temp1 ^ Temp2                  ' XOR THEM TOGTHER TO MAKE THE WHOLE BCD NUMBER 
Return

        
end  

Benzer Konular (5)

▲