⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtc-demo.asm

📁 DS1307 RTC real time clock header file for atmel AT89X5X
💻 ASM
📖 第 1 页 / 共 4 页
字号:

; CC5X Version 3.1I, Copyright (c) B Knudsen Data
; C compiler for the PICmicro family
; ************  23. Nov 2004  23:48  *************

	processor  16F88
	radix  DEC

INDF        EQU   0x00
PCL         EQU   0x02
FSR         EQU   0x04
PORTA       EQU   0x05
TRISA       EQU   0x85
PORTB       EQU   0x06
TRISB       EQU   0x86
PCLATH      EQU   0x0A
Carry       EQU   0
Zero_       EQU   2
RP0         EQU   5
RP1         EQU   6
IRP         EQU   7
GIE         EQU   7
OPTION_REG  EQU   0x81
RCSTA       EQU   0x18
TXREG       EQU   0x19
RCREG       EQU   0x1A
TXSTA       EQU   0x98
SPBRG       EQU   0x99
ANSEL       EQU   0x9B
EEDATA      EQU   0x10C
EEADR       EQU   0x10D
EEDATH      EQU   0x10E
EEADRH      EQU   0x10F
PEIE        EQU   6
TXIF        EQU   4
RCIF        EQU   5
CREN        EQU   4
SPEN        EQU   7
TXIE        EQU   4
RCIE        EQU   5
BRGH        EQU   2
SYNC        EQU   4
TXEN        EQU   5
RD          EQU   0
EEPGD       EQU   7
want_ints   EQU   0
want_ints_2 EQU   0
nate        EQU   0x3F
x           EQU   0x3F
nate_2      EQU   0x2E
my_byte     EQU   0x30
i           EQU   0x32
k           EQU   0x33
m           EQU   0x34
temp        EQU   0x35
high_byte   EQU   0x36
low_byte    EQU   0x37
C1cnt       EQU   0x3F
C2tmp       EQU   0x40
C3cnt       EQU   0x3F
C4tmp       EQU   0x40
C5rem       EQU   0x42
scl_IIC     EQU   0
sda_IIC     EQU   1
address     EQU   0x2C
thing       EQU   0x2E
address_2   EQU   0x2E
j           EQU   0x30
in_byte     EQU   0x31
nate_3      EQU   0x30
i_2         EQU   0x31
choice      EQU   0x20
x_2         EQU   0x2C
temp_2      EQU   0x2D
C6cnt       EQU   0x2E
C7tmp       EQU   0x2F
temp_3      EQU   0x21
cell        EQU   0x22
data_byte_in EQU   0x23
hours       EQU   0x24
minutes     EQU   0x25
seconds     EQU   0x26
am_pm       EQU   0
C8cnt       EQU   0x2C
C9tmp       EQU   0x2D
C10rem      EQU   0x2E
C11cnt      EQU   0x2C
C12tmp      EQU   0x2D
C13cnt      EQU   0x2C
C14tmp      EQU   0x2D
C15rem      EQU   0x2E
C16cnt      EQU   0x2C
C17tmp      EQU   0x2D
C18cnt      EQU   0x2C
C19tmp      EQU   0x2D
C20rem      EQU   0x2E
C21cnt      EQU   0x2C
C22tmp      EQU   0x2D
day         EQU   0x27
month       EQU   0x28
date        EQU   0x29
year        EQU   0x2A
C23cnt      EQU   0x2C
C24tmp      EQU   0x2D
C25rem      EQU   0x2E
C26cnt      EQU   0x2C
C27tmp      EQU   0x2D
C28cnt      EQU   0x2C
C29tmp      EQU   0x2D
C30rem      EQU   0x2E
C31cnt      EQU   0x2C
C32tmp      EQU   0x2D
C33cnt      EQU   0x2C
C34tmp      EQU   0x2D
C35rem      EQU   0x2E
C36cnt      EQU   0x2C
C37tmp      EQU   0x2D
ci          EQU   0x3F
TtmpA43     EQU   0x2B

	GOTO main

  ; FILE D:\Pics\code\16F88\RTC-Demo\rtc-demo.c
			;/*
			;    11-23-04
			;    Copyright Spark Fun Electronics 2004
			;
			;    Nathan Seidle
			;    spark@sparkfun.com    
			;
			;    This is the test bed firmware that we use to program the RTC Module using a PIC 16F88 at 20MHz. 
			;    It should give you some insight on how to deal with binary coded decimal as well as some software driven 
			;    I2C routines.
			;    
			;    Something interesting to note is that there is no external pull-up resistor on the SDA line (normally required
			;    for I2C communication). Instead, we turn on the internal pull-up resistors on the 16F88 PORTB pins every 
			;    time we do an I2C read. We don't use any hardware module on the 16F88, I just bit-bang I2C on any-ol port pins.
			;    
			;    This code is fairly bulky because of all the pretty-print menus. There is no checking during the programming routine.
			;    It is up to the user to select valid date ranges/month/times before hitting 'p' to program the RTC Module.
			;    
			;    We used Bloader/Screamer exclusively to design this code. That's why you won't see any config commands/bits.
			;    
			;*/
			;#define Clock_20MHz
			;#define Baud_9600
			;
			;#include "\Pics\c\16F88.h"  //Device dependent definitions
			;
			;#pragma origin 4
	ORG 0x0004

  ; FILE \Pics\code\stdio.c
			;/*
			;    5/21/02
			;    Nathan Seidle
			;    nathan.seidle@colorado.edu
			;    
			;    Serial Out Started on 5-21
			;    rs_out Perfected on 5-24
			;    
			;    1Wire Serial Comm works with 4MHz Xtal
			;    Connect Serial_Out to Pin2 on DB9 Serial Connector
			;    Connect Pin5 on DB9 Connector to Signal Ground
			;    9600 Baud 8-N-1
			;    
			;    5-21 My first real C and Pic program.
			;    5-24 Attempting 20MHz implementation
			;    5-25 20MHz works
			;    5-25 Serial In works at 4MHz
			;    5-25 Passing Strings 9:20
			;    5-25 Option Selection 9:45
			;
			;    6-9  'Stdio.c' created. Printf working with %d and %h
			;    7-20 Added a longer delay after rs_out
			;         Trying to get 20MHz on the 16F873 - I think the XTal is bad.
			;         20MHz also needs 5V Vdd. Something I dont have.
			;    2-9-03 Overhauled the 4MHz timing. Serial out works very well now.
			;    
			;    6-16-03 Discovered how to pass string in cc5x
			;        void test(const char *str);
			;        test("zbcdefghij"); TXREG = str[1];
			;        
			;        Moved to hardware UART. Old STDIO will be in goodworks.
			;        
			;        Works great! Even got the special print characters (\n, \r, \0) to work.
			;    
			;    4-25-04 Added new %d routine to print 16 bit signed decimal numbers without leading 0s.
			;        
			;
			;*/
			;
			;//Setup the hardware UART TX module
			;void enable_uart_TX(bit want_ints)
			;{
_const1
	RRF   ci+1,W
	ADDLW .0
	BSF   0x03,RP1
	MOVWF EEADRH
	BCF   0x03,RP1
	RRF   ci+1,W
	RRF   ci,W
	ADDLW .35
	BSF   0x03,RP1
	MOVWF EEADR
	BTFSC 0x03,Carry
	INCF  EEADRH,1
	BSF   0x03,RP0
	BSF   0x18C,EEPGD
	BSF   0x18C,RD
	NOP  
	NOP  
	BCF   0x03,RP0
	BCF   0x03,RP1
	BTFSC ci,0
	GOTO  m001
	BSF   0x03,RP1
	MOVF  EEDATA,W
	ANDLW .127
	BCF   0x03,RP1
	RETURN
m001	BSF   0x03,RP1
	RLF   EEDATA,W
	RLF   EEDATH,W
	BCF   0x03,RP1
	RETURN
	DW    0x68A
	DW    0x68A
	DW    0x1EBD
	DW    0x1EBD
	DW    0x1EBD
	DW    0x1EBD
	DW    0x2A52
	DW    0x1043
	DW    0x22C4
	DW    0x27CD
	DW    0x1EBD
	DW    0x1EBD
	DW    0x1EBD
	DW    0x1EBD
	DW    0x68A
	DW    0x2680
	DW    0x34E1
	DW    0x106E
	DW    0x32CD
	DW    0x3AEE
	DW    0x53A
	DW    0xD
	DW    0x18A0
	DW    0x1029
	DW    0x3950
	DW    0x33EF
	DW    0x30F2
	DW    0x106D
	DW    0x2A52
	DW    0x1043
	DW    0x37CD
	DW    0x3AE4
	DW    0x32EC
	DW    0x68A
	DW    0x1000
	DW    0x14B2
	DW    0x21A0
	DW    0x32E8
	DW    0x35E3
	DW    0x2920
	DW    0x21D4
	DW    0x2A20
	DW    0x36E9
	DW    0x565
	DW    0xD
	DW    0x68A
	DW    0x1D20
	DW    0x20
	DW    0x3463
	DW    0x34EF
	DW    0x32E3
	DW    0x1EA0
	DW    0x12A0
	DW    0x64
	DW    0x50A
	DW    0x218D
	DW    0x3975
	DW    0x32F2
	DW    0x3A6E
	DW    0x2A20
	DW    0x36E9
	DW    0x1065
	DW    0x3761
	DW    0x1064
	DW    0x30C4
	DW    0x32F4
	DW    0x53A
	DW    0x68A
	DW    0x1020
	DW    0x1000
	DW    0x102D
	DW    0x1900
	DW    0x30
	DW    0x68A
	DW    0x1020
	DW    0x28D3
	DW    0x1057
	DW    0x32D3
	DW    0x3A74
	DW    0x3769
	DW    0x39E7
	DW    0x1D20
	DW    0x12A0
	DW    0x1068
	DW    0x1280
	DW    0x1D64
	DW    0x1280
	DW    0x1064
	DW    0x2800
	DW    0x4D
	DW    0x26C1
	DW    0x500
	DW    0x100D
	DW    0x17E1
	DW    0x1073
	DW    0x3463
	DW    0x3761
	DW    0x32E7
	DW    0x31A0
	DW    0x3665
	DW    0x106C
	DW    0x107C
	DW    0x17AB
	DW    0x102D
	DW    0x3769
	DW    0x3963
	DW    0x30E5
	DW    0x32F3
	DW    0x322F
	DW    0x31E5
	DW    0x32F2
	DW    0x39E1
	DW    0x1065
	DW    0x107C
	DW    0x1070
	DW    0x37F4
	DW    0x3820
	DW    0x37F2
	DW    0x3967
	DW    0x36E1
	DW    0x68A
	DW    0x2980
	DW    0x3775
	DW    0x30E4
	DW    0x79
	DW    0x37CD
	DW    0x326E
	DW    0x3CE1
	DW    0x2A00
	DW    0x32F5
	DW    0x3273
	DW    0x3CE1
	DW    0x2B80
	DW    0x3265
	DW    0x32EE
	DW    0x3273
	DW    0x3CE1
	DW    0x2A00
	DW    0x3AE8
	DW    0x39F2
	DW    0x30E4
	DW    0x79
	DW    0x3946
	DW    0x3269
	DW    0x3CE1
	DW    0x2980
	DW    0x3A61
	DW    0x3975
	DW    0x30E4
	DW    0x79
	DW    0x30CA
	DW    0x3AEE
	DW    0x3961
	DW    0x79
	DW    0x32C6
	DW    0x3962
	DW    0x30F5
	DW    0x3CF2
	DW    0x2680
	DW    0x3961
	DW    0x3463
	DW    0x2080
	DW    0x3970
	DW    0x3669
	DW    0x2680
	DW    0x3CE1
	DW    0x2500
	DW    0x3775
	DW    0x65
	DW    0x3ACA
	DW    0x3CEC
	DW    0x2080
	DW    0x33F5
	DW    0x39F5
	DW    0x74
	DW    0x32D3
	DW    0x3A70
	DW    0x36E5
	DW    0x32E2
	DW    0x72
	DW    0x31CF
	DW    0x37F4
	DW    0x32E2
	DW    0x72
	DW    0x37CE
	DW    0x32F6
	DW    0x316D
	DW    0x3965
	DW    0x2200
	DW    0x31E5
	DW    0x36E5
	DW    0x32E2
	DW    0x72
	DW    0x12A0
	DW    0x1664
	DW    0x1000
	DW    0x1832
	DW    0x12B0
	DW    0x1064
	DW    0x1020
	DW    0x20
	DW    0x16A0
	DW    0x12AD
	DW    0x16E8
	DW    0x102D
	DW    0x0
enable_uart_TX
			;    BRGH = 0; //Normal speed UART
	BSF   0x03,RP0
	BCF   0x03,RP1
	BCF   0x98,BRGH
			;
			;    SYNC = 0;
	BCF   0x98,SYNC
			;    SPEN = 1;
	BCF   0x03,RP0
	BSF   0x18,SPEN
			;
			;#ifdef Clock_4MHz
			;    #ifdef Baud_9600
			;    SPBRG = 6; //4MHz for 9600 Baud
			;    #endif
			;#endif
			;
			;#ifdef Clock_8MHz
			;    #ifdef Baud_4800
			;    SPBRG = 25; //8MHz for 4800 Baud
			;    #endif
			;    #ifdef Baud_9600
			;    SPBRG = 12; //8MHz for 9600 Baud
			;    #endif
			;    #ifdef Baud_57600
			;    BRGH = 1; //High speed UART
			;    SPBRG = 7; //8MHz for 57600 Baud
			;    #endif
			;#endif
			;
			;#ifdef Crazy_Osc
			;    #ifdef Baud_9600
			;    SPBRG = 32; //20MHz for 9600 Baud
			;    #endif
			;#endif
			;
			;#ifdef Clock_20MHz
			;    #ifdef Baud_9600
			;    SPBRG = 31; //20MHz for 9600 Baud
	MOVLW .31
	BSF   0x03,RP0
	MOVWF SPBRG
			;    #endif
			;
			;    #ifdef Baud_4800
			;    SPBRG = 64; //20MHz for 4800 Baud
			;    #endif
			;#endif
			;
			;    if(want_ints) //Check if we want to turn on interrupts
	BTFSS 0x7F,want_ints
	GOTO  m002
			;    {
			;        TXIE = 1;
	BSF   0x8C,TXIE
			;        PEIE = 1;
	BSF   0x0B,PEIE
			;        GIE = 1;
	BSF   0x0B,GIE
			;    }
			;
			;    TXEN = 1; //Enable transmission
m002	BSF   0x98,TXEN
			;}    
	RETURN
			;
			;//Setup the hardware UART RX module
			;void enable_uart_RX(bit want_ints)
			;{
enable_uart_RX
			;
			;    BRGH = 0; //Normal speed UART
	BSF   0x03,RP0
	BCF   0x03,RP1
	BCF   0x98,BRGH
			;
			;    SYNC = 0;
	BCF   0x98,SYNC
			;    SPEN = 1;
	BCF   0x03,RP0
	BSF   0x18,SPEN
			;
			;#ifdef Clock_4MHz
			;    #ifdef Baud_9600
			;    SPBRG = 6; //4MHz for 9600 Baud
			;    #endif
			;#endif
			;
			;#ifdef Clock_8MHz
			;    #ifdef Baud_4800
			;    SPBRG = 25; //8MHz for 4800 Baud
			;    #endif
			;    #ifdef Baud_9600
			;    SPBRG = 12; //8MHz for 9600 Baud
			;    #endif
			;    #ifdef Baud_57600
			;    BRGH = 1; //High speed UART
			;    SPBRG = 8; //8MHz for 57600 Baud
			;    #endif
			;#endif
			;
			;#ifdef Crazy_Osc
			;    #ifdef Baud_9600
			;    SPBRG = 32; //20MHz for 9600 Baud
			;    #endif
			;#endif
			;
			;#ifdef Clock_20MHz
			;    #ifdef Baud_9600
			;    SPBRG = 31; //20MHz for 9600 Baud
	MOVLW .31
	BSF   0x03,RP0
	MOVWF SPBRG
			;    #endif
			;
			;    #ifdef Baud_4800
			;    SPBRG = 64; //20MHz for 4800 Baud
			;    #endif
			;#endif
			;
			;    CREN = 1;
	BCF   0x03,RP0
	BSF   0x18,CREN
			;
			;    //WREN = 1;
			;
			;    if(want_ints) //Check if we want to turn on interrupts
	BTFSS 0x7F,want_ints_2
	GOTO  m003
			;    {
			;        RCIE = 1;
	BSF   0x03,RP0
	BSF   0x8C,RCIE
			;        PEIE = 1;
	BSF   0x0B,PEIE
			;        GIE = 1;
	BSF   0x0B,GIE
			;    }
			;
			;}    
m003	BSF   0x03,RP0
	RETURN
			;
			;//Sends nate to the Transmit Register
			;void putc(uns8 nate)
			;{
putc
	MOVWF nate
			;    while(TXIF == 0);
m004	BTFSS 0x0C,TXIF
	GOTO  m004
			;    TXREG = nate;
	MOVF  nate,W
	MOVWF TXREG
			;}
	RETURN
			;
			;uns8 getc(void)
			;{
getc
			;    while(RCIF == 0);
m005	BTFSS 0x0C,RCIF
	GOTO  m005
			;    return (RCREG);
	MOVF  RCREG,W
	RETURN
			;}    
			;
			;//Returns ASCII Decimal and Hex values
			;uns8 bin2Hex(char x)
			;{
bin2Hex
	MOVWF x
			;   skip(x);
	MOVLW .1
	MOVWF PCLATH
	MOVF  x,W
	ADDWF PCL,1
			;   #pragma return[16] = "0123456789ABCDEF"
	RETLW .48
	RETLW .49
	RETLW .50
	RETLW .51
	RETLW .52
	RETLW .53
	RETLW .54
	RETLW .55
	RETLW .56
	RETLW .57
	RETLW .65
	RETLW .66
	RETLW .67
	RETLW .68
	RETLW .69
	RETLW .70
			;}
			;
			;//Prints a string including variables
			;void printf(const char *nate, int16 my_byte)
			;{
printf
			;  
			;    uns8 i, k, m, temp;
			;    uns8 high_byte = 0, low_byte = 0;
	CLRF  high_byte
	CLRF  low_byte
			;    uns8 y, z;
			;    
			;    uns8 decimal_output[5];
			;    
			;    for(i = 0 ; ; i++)
	CLRF  i
			;    {
			;        k = nate[i];
m006	MOVF  nate_2+1,W
	MOVWF ci+1
	MOVF  i,W
	ADDWF nate_2,W
	MOVWF ci
	BTFSC 0x03,Carry
	INCF  ci+1,1
	CALL  _const1
	MOVWF k
			;
			;        if (k == '\0') 
	MOVF  k,1
	BTFSC 0x03,Zero_
			;            break;
	GOTO  m029
			;
			;        else if (k == '%') //Print var
	XORLW .37
	BTFSS 0x03,Zero_
	GOTO  m027
			;        {
			;            i++;
	INCF  i,1
			;            k = nate[i];
	MOVF  nate_2+1,W
	MOVWF ci+1
	MOVF  i,W
	ADDWF nate_2,W
	MOVWF ci
	BTFSC 0x03,Carry
	INCF  ci+1,1
	CALL  _const1
	MOVWF k
			;
			;            if (k == '\0') 
	MOVF  k,1
	BTFSC 0x03,Zero_
			;                break;
	GOTO  m029
			;            else if (k == '\\') //Print special characters
	XORLW .92
	BTFSS 0x03,Zero_
	GOTO  m007
			;            {
			;                i++;
	INCF  i,1
			;                k = nate[i];
	MOVF  nate_2+1,W
	MOVWF ci+1
	MOVF  i,W
	ADDWF nate_2,W
	MOVWF ci
	BTFSC 0x03,Carry
	INCF  ci+1,1
	CALL  _const1
	MOVWF k
			;                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -