PIC Vietnam

Go Back   PIC Vietnam > Thành Viên

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

KVLV KVLV is offline

Đệ tử 2 túi

Visitor Messages

Showing Visitor Messages 1 to 1 of 1
  1. daovanduyet
    27-03-2013 04:43 PM
    daovanduyet
    anh oi em viết chương trình về nhiệt độ bằng picbasic pro như thế này
    '************************************************* ***************
    '* Name : nhiet do.BAS *
    '* Author : [DAO VAN DUYET] *
    '* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 3/25/2013 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    'DEFINE OSC 8
    DEFINE ADC_BITS 10
    Define ADC_CLOCK 2 ' Set clock source (4 : 4 TOSC)
    DEFINE ADC_SAMPLEUS 5


    ADCON1 = %00011100 ' %0001XXXX
    ' <=> "VREF-"-->MASS , "VREF+"-->PORTA.3
    ' %XXXX1100
    ' AN0,AN1,AN2 >> ANALOG

    ' AN0 : ADC VOLT - MAIN
    ' AN1 : ADC VOLT - CHARGE
    ' AN2 : CDS-PHOTORESISTOR
    ' AN3 : VREF+

    INPUT PORTA.5

    '************************************************* **************
    ' CONTROL LCD 16*2

    TRISB = %00000000
    ' OUTPUT PORTB.1
    ' OUTPUT PORTB.2
    ' OUTPUT PORTB.3
    ' OUTPUT PORTB.0
    ' OUTPUT PORTB.1

    OUTPUT PORTE.2

    '************************************************* ******************************************
    '* KHAI BAO LCD 20X4 *
    '* ********************* *
    '************************************************* ******************************************

    ' CAC BUOC KHAI BAO LCD
    ' KHONG DUNG CHAN RW - CHAN RW DUOC NOI XUONG MASS

    DEFINE LCD_BITS 4 ' CHI SU DUNG 4 BIT DE NHAP DATA CHO LCD
    DEFINE LCD_DREG PORTB ' DUNG 4 BIT CUA PORT B
    DEFINE LCD_DBIT 0 ' BIT DAU TIEN LA PORTB.0
    DEFINE LCD_RSREG PORTB ' DUNG PORTB DE DIEU KHIEN CHAN RS
    DEFINE LCD_EREG PORTB ' DUNG PORTB DE DIEU KHIEN CHAN E
    DEFINE LCD_RSBIT 4 ' PORTB.2 NOI VOI CHAN RS
    DEFINE LCD_EBIT 5 ' PORTB.3 NOI VOI CHAN E
    DEFINE LCD_LINES 2 ' LCD THUOC LOAI 2 DONG ( 16X2)



    '************************************************* ********************
    '************************************************* ********************
    ___BIEN_CHO_SENSOR_NHIET_DO_DS1820___ VAR BYTE
    DQ_IN VAR PORTE.2
    temperature Var Word ' Temperature storage
    count_remain Var WORD ' Count remaining
    count_per_c Var WORD ' Count per degree C
    count_remain = 0

    GOSUB CLEAR_LCD

    MAIN_PROGRAM :

    GOSUB READ_TEMP
    GOSUB LINE1
    LCDOUT " DAO VAN DUYET "
    GOSUB LINE2
    LCDOUT "NHIET DO = " ,DEC temperature/100,".",DEC temperature DIG 1," ",%11011111, "C "

    GOTO MAIN_PROGRAM

    '************************************************* ************************************************** **********
    '************************************************* ************************************************** **********
    '************************************************* ************************************************** **********
    BBBBBB :
    _________C_TRINH_DOC_NHIET_DO_____ :
    BBBBBBB:
    '************************************************* ************************************************** **********
    '************************************************* ************************************************** **********
    '************************************************* ************************************************** **********

    READ_TEMP :

    OWOut DQ_IN,1,[$CC,$44] ' Start temperature conversion
    GOSUB DELAY_DS1820
    OWOut DQ_IN,1,[$CC,$BE] ' Read the temperature
    GOSUB DELAY_DS1820
    OWIN DQ_IN, 0, [temperature.LOWBYTE,temperature.HIGHBYTE]
    temperature = temperature */ 1600

    RETURN


    '************************************************* *********************************************
    ' CHUONG TRINH CON DIEU KHIEN LCD
    ' ***********************************
    '************************************************* *********************************************
    IIIIIIIIIIII :
    ______CHUONG_TRINH_DIEU_KHIEN_LCD______ :
    IIIIIIIIIIIII :
    CLEAR_LCD :

    LCDOUT $FE , $1
    GOSUB DELAY_LCD
    RETURN

    '************************************************

    LINE1 :
    LCDOUT $FE , $2
    GOSUB DELAY_LCD
    RETURN

    LINE2 :

    LCDOUT $FE , $C0
    GOSUB DELAY_LCD
    RETURN

    IIIIIIIIIIIIIIIIIIII :
    __________CAC_CHUONG_TRINH_DELAY_________ :
    IIIIIIIIIIIIIIIIIIIII :
    DELAY_ADC :
    PAUSEUS 50
    RETURN

    DELAY_LCD :
    PAUSEUS 50
    RETURN

    DELAY_DS1820 :
    PAUSE 200
    RETURN

    em muốn là nếu nhiệt độ dưới 15 độ C hoặc trên 40 độ C thì báo động vậy thì em viết thêm như thế nào ạ?
    anh có thể chỉ cho em với không ạ?

Statistics

Tổng số bai
Visitor Messages
General Information
  • Lần cuối: 16-06-2013 11:08 PM
  • Tham gia ngày: 04-08-2010
  • Ðã giới thiệu: 0

Múi giờ GMT. Hiện tại là 10:51 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam