Code:
To mafd_47a:
//************************************************** ***********
Tớ rất thích chữ kí của bạn! rất đúng đó
Code:
ONE WORK, ONE PURPOSE or NOTHING!
To mafd_47a:
ONE WORK, ONE PURPOSE or NOTHING!
; *******************************************************
;
; Dallas 1-Wire Support for PIC16F628
;
; Processor has 4MHz clock and 1s per instruction cycle.
;
; *******************************************************
; *******************************************************
; Dallas Semiconductor 1-Wire MACROS
; *******************************************************
WRITE_SENTENCE: MACRO POS,DONG,CHUOI,WRITE,VITRICONTRO
MOVLW POS
CALL DONG
CLRF R1
AGAIN1 MOVF R1,W
CALL CHUOI
ADDLW 0x00
BTFSC STATUS,Z
GOTO NEXT1
CALL WRITE
INCF R1,F
GOTO AGAIN1
MOVLW POS
ADDWF R1,W
MOVWF VITRICONTRO ; Luu con tro cua LCD vao bien
NEXT1
ENDM
OW_HIZ:MACRO
BSF STATUS,RP0 ; Select Bank 1 of data memory
BSF TRISB, DQ ; Make DQ pin High Z
BCF STATUS,RP0 ; Select Bank 0 of data memory
ENDM
; --------------------------------------------------------
OW_LO:MACRO
BCF STATUS,RP0 ; Select Bank 0 of data memory
BCF PORTB, DQ ; Clear the DQ bit
BSF STATUS,RP0 ; Select Bank 1 of data memory
BCF TRISB, DQ ; Make DQ pin an output
BCF STATUS,RP0 ; Select Bank 0 of data memory
ENDM
; --------------------------------------------------------
WAIT:MACRO TIME
;Delay for TIME s.
;time must be in multiples of 5s.
MOVLW (TIME/5)-1 ;1s
MOVWF TMP0 ;1s
CALL WAIT5U ;2s
ENDM
; *******************************************************
; Dallas Semiconductor 1-Wire ROUTINES
; *******************************************************
WAIT5U:
;This takes 5uS to complete
NOP ;1s
NOP ;1s
DECFSZ TMP0,F ;1s or 2s
GOTO WAIT5U ;2s
RETLW 0 ;2s
; --------------------------------------------------------
OW_RESET:
OW_HIZ ; Start with the line high
CLRF PDBYTE ; Clear the PD byte
OW_LO
WAIT .500 ; Drive Low for 500s
OW_HIZ
WAIT .70 ; Release line and wait 70s for PD Pulse
BTFSS PORTB,DQ ; Read for a PD Pulse
INCF PDBYTE,F ; Set PDBYTE to 1 if get a PD Pulse
WAIT .400 ; Wait 400s after PD Pulse
RETLW 0
; --------------------------------------------------------
DSRXBYTE: ; Byte read is stored in IOBYTE
MOVLW .8
MOVWF COUNT ; Set COUNT equal to 8 to count the bits
DSRXLP:
OW_LO
NOP
NOP
NOP
NOP
NOP
NOP ; Bring DQ low for 6s
OW_HIZ
NOP
NOP
NOP
NOP ; Change to HiZ and Wait 4s
MOVF PORTB,W ; Read DQ
ANDLW 1<<DQ ; Mask off the DQ bit
ADDLW .255 ; C=1 if DQ=1: C=0 if DQ=0
RRF IOBYTE,F ; Shift C into IOBYTE
WAIT .50 ; Wait 50s to end of time slot
DECFSZ COUNT,F ; Decrement the bit counter
GOTO DSRXLP
RETLW 0
; --------------------------------------------------------
DSTXBYTE: ; Byte to send starts in W
MOVWF IOBYTE ; We send it from IOBYTE
MOVLW .8
MOVWF COUNT ; Set COUNT equal to 8 to count the bits
DSTXLP:
OW_LO
NOP
NOP
NOP
NOP
NOP ; Drive the line low for 5s
RRF IOBYTE,F ; The data byte
BTFSC STATUS,C ; Check the LSB of IOBYTE for 1 or 0
BSF PORTB,DQ ; Drive the line high if LSB is 1
WAIT .60 ; Continue driving line for 60s
OW_HIZ ; Release the line for pullup
NOP
NOP ; Recovery time of 2s
DECFSZ COUNT,F ; Decrement the bit counter
GOTO DSTXLP
RETLW 0
; --------------------------------------------------------
;**********************************************************************
; *
; Filename: DS1307.asm *
; Date: 28-10-2005 *
; File Version: V1.0 *
; *
; Author: MAFD_47A *
; Company: BACHKHOA *
; *
; *
;**********************************************************************
; *
; Files required: Ket noi PIC16f88 voi DS1821 hien thi len LCD *
; *
; *
; *
;**********************************************************************
; *
; Notes: EN noi voi chan 7 *
; RS noi voi chan 6 *
; RW noi voi chan 3 *
; Data noi tu 3,2,1,0 (portA) voi D7,D6,D5,D4 cua LCD *
; Su dung thach anh 4MH *
; Noi DQ cua DS1821 voi chan RA$ cua VDK *
; *
;**********************************************************************
; *
; Upgrade: *
; *
;**********************************************************************
list p=16f88 ; list directive to define processor
#include <p16F88.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file & _WRT_ENABLE_OFF
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
w_temp EQU 0x71 ; variable used for context saving
status_temp EQU 0x72 ; variable used for context saving
pclath_temp EQU 0x73 ; variable used for context saving
ACC EQU 0x74
MODE EQU 0x75
R0 EQU 0x78
R1 EQU 0x79
R2 EQU 0x7A
R3 EQU 0x7B
R4 EQU 0x7C
R5 EQU 0x7D
R6 EQU 0x7E
R7 EQU 0x7F
EN EQU H'0007'
RS EQU H'0006'
RW EQU H'0003'
P7 EQU H'0007'
START_RAM EQU 0x60
I2C EQU 0x00
PORT_DAT EQU PORTA
TRIS_DAT EQU TRISA
PORT_CON EQU PORTB
TRIS_CON EQU TRISB
DQ EQU 0x04
cblock 0x20
IOBYTE
TMP0 ; Address 0x23
COUNT ; Keep track of bits
PICMSB ; Store the MSB
PICLSB ; Store the LSB
PDBYTE ; Presence Detect Pulse
VITRI ; Dung de luu bien cua vi tri con tro trong LCD
S100 ; Gia tri hang 100
S10 ; Gia tri hang chuc
S1 ; Gia tri hang don vi
endc
ORG 0x0000
goto MAIN
ORG 0x0004
movwf w_temp ; save off current W register contents
movf STATUS,w ; move STATUS register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,W ; move PCLATH register into W register
movwf pclath_temp ; save off contents of PCLATH register
;==============================================================================
;==============================================================================
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
include <1W_16F6X.inc>
MAIN
BANKSEL ANSEL
CLRF ANSEL
BANKSEL PORTA
CALL INIT_LCD
;====================================================================
WRITE_SENTENCE 0x03,GOTOLINE1,MYDATA,WRITE_TEXT,VITRI
CALL INIT_TEMP
MOVLW 0x08
MOVWF VITRI
AGAIN CALL DELAY255
CALL DELAY255
CALL DELAY255
CALL DELAY255
CALL GET_TEMP
INCF IOBYTE,F
CALL WRITE_TEMP
GOTO AGAIN
;====================================================================
MYDATA ADDWF PCL,F
RETLW 'T'
RETLW 'E'
RETLW 'M'
RETLW 'P'
RETLW ':'
RETLW ' '
RETLW 0x00
INIT_TEMP
CALL OW_RESET
MOVLW 0x01
CALL DSTXBYTE
MOVLW .40
CALL DSTXBYTE
CALL OW_RESET
MOVLW 0x02
CALL DSTXBYTE
MOVLW .10
CALL DSTXBYTE
CALL OW_RESET
MOVLW 0x0C
CALL DSTXBYTE
MOVLW B'01000000'
CALL DSTXBYTE
CALL OW_RESET
MOVLW 0xEE
CALL DSTXBYTE
RETURN
GET_TEMP
CALL OW_RESET
MOVLW 0xAA
CALL DSTXBYTE
CALL DSRXBYTE ; GIA TRI NHIET DO DA DUOC LUU VAO IOBYTE
RETURN
WRITE_TEMP
MOVF IOBYTE,W
CALL CONVERT_BCD
MOVF R2,W ; Luu cac gia tri r2,r1,r0 vao cac bien s100,s10,s1
MOVWF S100
MOVF R1,W
MOVWF S10
MOVF R0,W
MOVWF S1
MOVF VITRI,W
CALL GOTOLINE1
MOVF S100,W
ADDLW 0x00
BTFSC STATUS,Z
MOVLW 0xE0
ADDLW 0x30
CALL WRITE_TEXT
MOVF S10,W
ADDLW 0x30
CALL WRITE_TEXT
MOVF S1,W
ADDLW 0x30
CALL WRITE_TEXT
RETLW 0x00
CONVERT_BCD ; In W, out: R2,R1,R0 ( hang tram chu, don vi )
MOVWF ACC ; Luu vao trong ACC lam thanh ghi dem
CLRF R0 ; Xoa cac thanh ghi de luu RA DANG gia tri out
CLRF R1
CLRF R2
MOVLW .100
BCD_100 ; Voi so hang chuc
INCF R2,F
SUBWF ACC,F
BTFSC STATUS,C
GOTO BCD_100
DECF R2,F
ADDWF ACC,F
MOVLW .10
BCD_10 ; Voi so hang chuc
INCF R1,F
SUBWF ACC,F
BTFSC STATUS,C
GOTO BCD_10
DECF R1,F
ADDWF ACC,W
MOVWF R0
RETURN
DELAY255 movlw 0xff ;delay 255 mS
goto D0
DELAY100 movlw d'100' ;delay 100mS
goto D0
DELAY50 movlw d'50' ;delay 50mS
goto D0
DELAY20 movlw d'20' ;delay 20mS
goto D0
DELAY5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
D0 movwf R2
D1 movlw 0xC7 ;delay 1mS
movwf R3
movlw 0x01
movwf R4
Delay_0
decfsz R3, f
goto $+2
decfsz R4, f
goto Delay_0
decfsz R2 ,f
goto D1
retlw 0x00
END
I'm beginner.#include <16F88.H>
#include <ctype.h>
#fuses INTRC_IO,NOWDT
#use delay(clock=8000000)
#use rs232(baud=19200,xmit=PIN_B5, rcv=PIN_B2,enable=PIN_B4,errors,stream=HOSTPC)
#define TRIS_A 0xFF //0b11111111 //Tat ca la dau vao
#define TRIS_B 0xC4 //0b11000100
#define RTCC_RVALUE 6 //=256 - ((8000000/4)/RTCC_DIV_8)/1000 (Ngat 1000 lan/giay)
#define DO2 PIN_B0 //Led
int16 LedTimeout;
void InitPar()
{
set_tris_a(TRIS_A);
set_tris_b(TRIS_B);
}
void InitRTCC(void)
{
set_rtcc(RTCC_RVALUE); // Khoi tao timer0
setup_counters (RTCC_INTERNAL, RTCC_DIV_8);
enable_interrupts (INT_RTCC);
}
#INT_RTCC
clock_isr()
//Ngat nay se tran sau 1000us
{
disable_interrupts(INT_RTCC);
if (++LedTimeout > 1000)
{
output_toggle(DO2);
LedTimeout = 0;
}
set_rtcc(RTCC_RVALUE);
enable_interrupts(INT_RTCC);
}
...
Comment