Şimdi Ara

Pic Basic te USART kullanımı...

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
2
Cevap
0
Favori
1.939
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Arkadaşlar yapmakta olduğum bitirme projesinde barcod okuyucu kullanmaktayım..
    barcod okuyucan ne zaman bilgi geleceği belli olmadığında kesme kullanmanın daha mantıklı olacağını düşünüyorum..
    Yani serin2 komutuyla şuan istediğim işi yaptırabiliyorum ama
    mesela pic o anda başka bir komut icra ederken barcod dan veri gelirse ne olacak??
    pic basic pro ile bu projem dolayısı ile uğraşmaya başladım ve araştırmalarım beni USART modulune götürdü..
    HSERİn komutuyla pic i meşgul etmeden seri veri alıp yollayabiliyormuşuz ??

    usart modulu bu bilgiyi işlemciden tamamen bağımsız bi şekilde alıp , rcreg kayıtçısına kaydeder ve kesme atıyormuş...

    Lakin bunları bulmama rağmen konuyla ilgili bir örnek bulamadığımdan tıkanmış durumdayım??

    bana bunun kesme kullanarak örneklendirecek bir arkadaş arıyorum.. Yada konuyla ilgili bir döküman..

    Projemi 1 aya bitirmem gerekiyor.. şimd,d,en yardımcı olan arkadaşlara çok teşekkürler..







  • Yoğun aramalarım sonucunda yabancı bir sitede aşağıdaki kodu bulldum.. İşin mantığını anlamam bakımından bayağa faydalı oldu...

    kesmeyi alıyor ama 1 ve 2 olma durumuna göre belirlenen led ler yanmıyor???
    bi incelerseniz sevinirim..
    Hyperterminal le denedim



    ' Simple program to handle USART interrupt using PIC16F877
    ' ===============================================================
    '
    ' This program will Blink a LED on PORTB.0 to show
    ' that the PIC is running.
    '
    ' This program also allow the user to activate or deactivate
    ' a LED connected on PORTB.1 pin by sending command from a PC
    ' terminal software using 9600,n,8,1 setting
    '
    ' User command:
    ' =============
    ' 1. If character "1" is received => enable the LED
    ' 2. if character "2" is received => disable the LED
    '
    '

    ' PORT setting
    ' ============
    '
    TRISC=%10000000 ' RC.7 => USART RX pin set to input
    ' all other pin set to output
    '
    TRISB=0 ' RB<7:0> set to output

    ' USART setting
    ' =============
    ' Since we will not use HSERIN/HSEROUT, we must
    ' write directly to internal PIC register
    '
    TXSTA=$24 ' enable transmit and SPBRGH=1
    RCSTA=$90 ' Enable USART and continuous receive
    SPBRG=129 ' BAUD RATE = 9600 BAUDS

    ' Interrupt definition
    ' ====================
    '
    PIE1.5 =1 ' enable USART receive interrupt
    INTCON.6 =1 ' enable peripheral interrupt

    ' Alias definition
    ' ================
    '
    RCIF var PIR1.5 ' receiver interrupt
    StatusLED var PORTB.0 ' the LED who show a 'running process'
    UserLED var PORTB.1 ' the LED that user want to control

    ' Variable definition
    ' ===================
    '
    Delay var word '
    DataIn var byte ' use to store RCREG content
    Discard var byte ' use to erase RCREG register

    ' Hardware/software initialisation
    ' ================================
    '
    PORTB=0 ' clear PORTB
    on interrupt goto USARTInterrupt

    Start:
    ' Main program loop that make the user happy to
    ' see a LED flashing to mean that something is
    ' running
    '
    toggle statusled
    for delay = 1 to 5000 ' use a loop delay to ensure
    pauseus 5 ' getting interrupt as fast as
    next ' possible
    goto start


    disable interrupt
    USARTInterrupt:
    ' Here's the interrupt routine who will make the user
    ' much happy by giving him the feeling to have the
    ' control on the machine when the status of the user
    ' LED will change
    '
    RCSTA=0 ' Disable serial port AND
    ' clear possible error (FERR,OERR)

    datain=RCREG ' Get data

    while RCif ' wait untill the RCREG is empty
    discard=RCREG ' by reading it and store result in a
    wend ' don't care variable

    select case datain ' What to do with that data???

    case "1" ' User selection = 1
    userled=1 ' => Enable the LED

    case "2" ' User selection =2
    userled=0 ' => disable the LED

    end select
    RCSTA=$90 ' Re-enable the serial PORT AND
    resume ' get out of here
    enable interrupt



    < Bu mesaj bu kişi tarafından değiştirildi Command.com -- 7 Mayıs 2007; 2:38:20 >




  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.