?? lcd1602pbpd.s
字號:
.module Lcd1602PBPD.C
.area text(rom, con, rel)
; y -> y+4
; j -> y+0
; i -> R10
; len -> y+18
; dat -> y+14
.even
_speaData::
xcall push_arg4
xcall push_xgsetF00C
sbiw R28,8
; /*********************************************************************
; 微 雪 電 子 WaveShare http://www.waveShare.net
;
; 目 的: 建立AVR的軟件提取庫,增加各類補丁,方便系統程序移植
;
; 目標系統: 基于AVR單片機
;
; 應用軟件: ICCAVR
;
; 版 本: Version 1.0
;
; 圓版時間: 2005-06-25
;
; 開發人員: SEE
;
; 說 明: 若用于商業用途,請保留此段文字或注明代碼來源
;
; 深 圳 市 微 雪 電 子 有 限 公 司 保 留 所 有 的 版 權
; *********************************************************************/
;
; /*01010101010101010101010101010101010101010101010101010101010101010101
; ----------------------------------------------------------------------
; 版本更新記錄:
;
; ----------------------------------------------------------------------
; 入口參數說明:
;
; ----------------------------------------------------------------------
; 待定參數說明:
;
; ----------------------------------------------------------------------
; 對外變量說明:
;
; ----------------------------------------------------------------------
; 對外函數說明:
;
; ----------------------------------------------------------------------
; 10101010101010101010101010101010101010101010101010101010101010101010*/
;
; #ifndef Software_H
; #define Software_H
;
; #include <math.h>
; #include <string.h>
;
; /* 兼容一般程序員的常用寫法 */
; typedef unsigned char uchar;
; typedef unsigned int uint;
; typedef unsigned long ulong;
; typedef signed char schar;
; typedef signed int sint;
; typedef signed long slong;
;
; /* 為方便移植,建議使用下面寫法 */
; typedef unsigned char bool;
; typedef unsigned char uint8;
; typedef unsigned int uint16;
; typedef unsigned long uint32;
; typedef signed char sint8;
; typedef signed int sint16;
; typedef signed long sint32;
; typedef signed char int8;
; typedef signed int int16;
; typedef signed long int32;
;
; /* 下面寫法一般不推薦 */
; //typedef unsigned char ubyte;
; //typedef unsigned int uword;
; //typedef unsigned long udword;
; //typedef signed char sbyte;
; //typedef signed int sword;
; //typedef signed long sdword;
;
; /* 一般程序定義的默認值 */
; //#define NULL 0
; //#define EOF -1
; //#define TRUE 1
; //#define FALSE 0
; //#define YES 1
; //#define NO 0
; //#define ON 1
; //#define OFF 0
; //#define ENABLE 1
; //#define DISABLE 0
; //#define CRR 1
; //#define ERR 0
; //#define RIGHT 1
; //#define WRONG 0
; //#define SUCCESS 1
; //#define FAILURE 0
; //#define PI 3.1415926 //3.1415926535897932
;
; /* 如果你手頭上的RAM實在很緊,不如嘗試下面的define~ */
; //#define _CALLOC(a) ( (a *)calloc(n,sizeof(a)) )
; //#define _MALLOC(a) ( (a *)malloc(sizeof(a)) )
; //#define _MIN(a,b) ( (a) < (b) ? (a) : (b) )
; //#define _MAX(a,b) ( (a) > (b) ? (a) : (b) )
; //#define _EXCHANGE(a,b) { int t; t=a; a=b; b=t; }
; //#define _TOLOWER(c) ( (c)+32 )
; //#define _TOUPPER(c) ( (c)-32 )
;
; //#ifndef BIT
; //#define BIT(x) ( 1<<(x) )
; //#endif
;
; /*--------------------------------------------------------------------
; 函數全稱:數據拆字
; 函數功能:
; 注意事項:D<=999999,C<=6
; 提示說明:調用speaData(12,2),得到dataElem[0]=2,dataElem[1]=1
; 輸 入:
; 返 回:無
; --------------------------------------------------------------------*/
; uint8 dataElem[6];
; void speaData(uint32 dat,sint8 len)
; {
; uint8 i;
; uint32 j,y;
; for(i=0,j=1;i<len;i++)
clr R10
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
std y+0,R20
std y+1,R21
std y+2,R22
std y+3,R23
xjmp L5
L2:
; {
; y=dat/j;
ldd R2,y+0
ldd R3,y+1
ldd R4,y+2
ldd R5,y+3
ldd R16,y+14
ldd R17,y+15
ldd R18,y+16
ldd R19,y+17
st -y,R5
st -y,R4
st -y,R3
st -y,R2
xcall div32u
std y+4,R16
std y+5,R17
std y+6,R18
std y+7,R19
; dataElem[i]=y%10;
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
ldd R16,y+4
ldd R17,y+5
ldd R18,y+6
ldd R19,y+7
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall mod32u
ldi R24,<_dataElem
ldi R25,>_dataElem
mov R30,R10
clr R31
add R30,R24
adc R31,R25
std z+0,R16
; j*=10;
ldd R2,y+0
ldd R3,y+1
ldd R4,y+2
ldd R5,y+3
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
std y+0,R16
std y+1,R17
std y+2,R18
std y+3,R19
; }
L3:
inc R10
L5:
ldd R2,y+18
clr R3
sbrc R2,7
com R3
mov R4,R10
clr R5
cp R4,R2
cpc R5,R3
brge X1
xjmp L2
X1:
X0:
L1:
.dbline 0 ; func end
adiw R28,8
xcall pop_xgsetF00C
adiw R28,4
ret
.even
_I2C_Start::
; /*********************************************************************
; 微 雪 電 子 WaveShare http://www.waveShare.net
;
; 目 的: 建立I2C操作庫
;
; 目標系統: 基于AVR單片機
;
; 應用軟件: ICCAVR
;
; 版 本: Version 1.0
;
; 圓版時間: 2005-06-25
;
; 開發人員: SEE
;
; 說 明: 若用于商業用途,請保留此段文字或注明代碼來源
;
; 深 圳 市 微 雪 電 子 有 限 公 司 保 留 所 有 的 版 權
; *********************************************************************/
;
; /*01010101010101010101010101010101010101010101010101010101010101010101
; ----------------------------------------------------------------------
; 版本更新記錄:
;
; ----------------------------------------------------------------------
; 入口參數說明:
;
; ----------------------------------------------------------------------
; 待定參數說明:
;
; ----------------------------------------------------------------------
; 對外變量說明:
;
; ----------------------------------------------------------------------
; 對外函數說明:
;
; ----------------------------------------------------------------------
; 10101010101010101010101010101010101010101010101010101010101010101010*/
;
; #ifndef I2C_H
; #define I2C_H
;
; #include "D:\ICC_H\CmmICC.H"
;
; /* TWSR values (not bits) */
; /* Master */
; #define I2C_START 0x08
; #define I2C_RESTART 0x10
;
; /* Master Transmitter */
; #define I2C_MT_SLA_ACK 0x18
; #define I2C_MT_SLA_NACK 0x20
; #define I2C_MT_DATA_ACK 0x28
; #define I2C_MT_DATA_NACK 0x30
; #define I2C_MT_ARB_LOST 0x38
;
; /* Master Receiver */
; #define I2C_MR_ARB_LOST 0x38
; #define I2C_MR_SLA_ACK 0x40
; #define I2C_MR_SLA_NACK 0x48
; #define I2C_MR_DATA_ACK 0x50
; #define I2C_MR_DATA_NACK 0x58
;
; /* Slave Transmitter */
; #define I2C_ST_SLA_ACK 0xA8
; #define I2C_ST_ARB_LOST_SLA_ACK 0xB0
; #define I2C_ST_DATA_ACK 0xB8
; #define I2C_ST_DATA_NACK 0xC0
; #define I2C_ST_LAST_DATA 0xC8
;
; /* Slave Receiver */
; #define I2C_SR_SLA_ACK 0x60
; #define I2C_SR_ARB_LOST_SLA_ACK 0x68
; #define I2C_SR_GCALL_ACK 0x70
; #define I2C_SR_ARB_LOST_GCALL_ACK 0x78
; #define I2C_SR_DATA_ACK 0x80
; #define I2C_SR_DATA_NACK 0x88
; #define I2C_SR_GCALL_DATA_ACK 0x90
; #define I2C_SR_GCALL_DATA_NACK 0x98
; #define I2C_SR_STOP 0xA0
;
; /* Misc */
; #define I2C_NO_INFO 0xF8
; #define I2C_BUS_ERROR 0x00
;
; /*
; * The lower 3 bits of TWSR are reserved on the ATmega163.
; * The 2 LSB carry the prescaler bits on the newer ATmegas.
; */
; #define I2C_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))
; #define I2C_STATUS (TWSR & I2C_STATUS_MASK)
;
; /*
; * R/~W bit in SLA+R/W address field.
; */
; #define I2C_READ 1
; #define I2C_WRITE 0
;
; #define I2CStart() (TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN))
; #define I2CStop() (TWCR=(1<<TWINT)|(1<<TWSTO)|(1<<TWEN))
; #define I2CWaitAck() {while(!(TWCR&(1<<TWINT)));}
; #define I2CChkAck() (TWSR&0xf8) //check ack
; #define I2CSendAck() (TWCR|=(1<<TWEA))
; #define I2CSendNoAck() (TWCR&=~(1<<TWEA))
; #define I2CSendByte(x) {TWDR=(x);TWCR=(1<<TWINT)|(1<<TWEN);}
; #define I2CRcvNckByte() (TWCR=(1<<TWINT)|(1<<TWEN))
; #define I2CRcvAckByte() (TWCR=(1<<TWINT)|(1<<TWEN)|(1<<TWEA))
;
; /* For Program */
; #define I2C_Stop() I2CStop()
; #define I2C_SendAck() I2CSendAck()
; #define I2C_SendNoAck() I2CSendNoAck()
; #define I2C_WaitAck() I2CWaitAck()
;
; /* I2C Config */
; #define I2C_ERR 0
; #define I2C_CRR 1
;
; /*--------------------------------------------------------------------
; 函數名稱:I2C Start
; 函數功能:
; 注意事項:
; 提示說明:
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_Start()
; {
; I2CStart();
ldi R24,164
out 0x36,R24
; I2CWaitAck();
L7:
L8:
in R2,0x36
sbrs R2,7
rjmp L7
X2:
; if( I2CChkAck()!=I2C_START )
in R24,0x1
andi R24,248
cpi R24,8
breq L10
X3:
; return I2C_ERR;
clr R16
xjmp L6
L10:
; return I2C_CRR;
ldi R16,1
L6:
.dbline 0 ; func end
ret
.even
_I2C_Restart::
; }
; /*--------------------------------------------------------------------
; 函數名稱:I2C ReStart
; 函數功能:
; 注意事項:
; 提示說明:
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_Restart()
; {
; I2CStart();
ldi R24,164
out 0x36,R24
; I2CWaitAck();
L13:
L14:
in R2,0x36
sbrs R2,7
rjmp L13
X4:
; if( I2CChkAck()!=I2C_RESTART )
in R24,0x1
andi R24,248
cpi R24,16
breq L16
X5:
; return I2C_ERR;
clr R16
xjmp L12
L16:
; return I2C_CRR;
ldi R16,1
L12:
.dbline 0 ; func end
ret
; wrDAdr -> R16
.even
_I2C_SendWrDAdr::
; }
; /*--------------------------------------------------------------------
; 函數名稱:發送 7位 器件寫地址: XXXX XXX0
; 函數功能:
; 注意事項:
; 提示說明:
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_SendWrDAdr(uint8 wrDAdr)
; {
; I2CSendByte(wrDAdr); //設置 器件寫地址
out 0x3,R16
ldi R24,132
out 0x36,R24
; I2CWaitAck();
L19:
L20:
in R2,0x36
sbrs R2,7
rjmp L19
X6:
; if( I2CChkAck()!=I2C_MT_SLA_ACK )
in R24,0x1
andi R24,248
cpi R24,24
breq L22
X7:
; return I2C_ERR;
clr R16
xjmp L18
L22:
; return I2C_CRR;
ldi R16,1
L18:
.dbline 0 ; func end
ret
; wrDAdr -> R10,R11
.even
_I2C_SendWrDAdr_::
st -y,R10
st -y,R11
movw R10,R16
; }
; /*--------------------------------------------------------------------
; 函數名稱:發送 10位 器件寫地址: 1111 0XX0, XXXX XXXX
; 函數功能:
; 注意事項:
; 提示說明:兼容 發送 7位 器件寫地址: XXXX XXX0
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_SendWrDAdr_(uint16 wrDAdr)
; {
; if( wrDAdr&0xF000 == 0xF000 ) //判斷是否為 10位 器件地址
sbrs R10,0
rjmp L25
X8:
; if( I2C_SendWrDAdr( (uint8)wrDAdr>>8 )==I2C_ERR ) //設置 (高位)器件寫地址
mov R16,R10
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
xcall _I2C_SendWrDAdr
tst R16
brne L27
X9:
; return I2C_ERR;
clr R16
xjmp L24
L27:
L25:
; if( I2C_SendWrDAdr( (uint8)wrDAdr )==I2C_ERR ) //設置 (低位)器件寫地址
mov R16,R10
xcall _I2C_SendWrDAdr
tst R16
brne L29
X10:
; return I2C_ERR;
clr R16
xjmp L24
L29:
; return I2C_CRR;
ldi R16,1
L24:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
; rdDAdr -> R16
.even
_I2C_SendRdDAdr::
; }
; /*--------------------------------------------------------------------
; 函數名稱:發送 7位 器件讀地址: XXXX XXX1
; 函數功能:
; 注意事項:
; 提示說明:
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_SendRdDAdr(uint8 rdDAdr)
; {
; I2CSendByte(rdDAdr); //設置 器件讀地址
out 0x3,R16
ldi R24,132
out 0x36,R24
; I2CWaitAck();
L32:
L33:
in R2,0x36
sbrs R2,7
rjmp L32
X11:
; if( I2CChkAck()!=I2C_MR_SLA_ACK )
in R24,0x1
andi R24,248
cpi R24,64
breq L35
X12:
; return I2C_ERR;
clr R16
xjmp L31
L35:
; return I2C_CRR;
ldi R16,1
L31:
.dbline 0 ; func end
ret
; rdDAdr -> R10
.even
_I2C_SendRdDAdr_::
st -y,R10
mov R10,R16
; }
; /*--------------------------------------------------------------------
; 函數名稱:發送 10位 器件讀地址: 1111 0XX0, XXXX XXXX
; 函數功能:
; 注意事項:
; 提示說明:
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_SendRdDAdr_(uint8 rdDAdr)
; {
; if( rdDAdr&0xF000 == 0xF000 ) //判斷是否為 10位 器件地址
sbrs R10,0
rjmp L38
X13:
; if( I2C_SendWrDAdr( (uint8)rdDAdr>>8 )==I2C_ERR ) //設置 (高位)器件讀地址
mov R16,R10
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
lsr R16
xcall _I2C_SendWrDAdr
tst R16
brne L40
X14:
; return I2C_ERR;
clr R16
xjmp L37
L40:
L38:
; if( I2C_SendWrDAdr( (uint8)rdDAdr )==I2C_ERR ) //設置 (低位)器件讀地址
mov R16,R10
xcall _I2C_SendWrDAdr
tst R16
brne L42
X15:
; return I2C_ERR;
clr R16
xjmp L37
L42:
; return I2C_CRR;
ldi R16,1
L37:
.dbline 0 ; func end
ld R10,y+
ret
; configDat -> R16
.even
_I2C_SendDat::
; }
; /*--------------------------------------------------------------------
; 函數名稱:I2C發送數據
; 函數功能:
; 注意事項:
; 提示說明:
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_SendDat(uint8 configDat)
; {
; I2CSendByte(configDat);
out 0x3,R16
ldi R24,132
out 0x36,R24
; I2CWaitAck();
L45:
L46:
in R2,0x36
sbrs R2,7
rjmp L45
X16:
; if( I2CChkAck()!=I2C_MT_DATA_ACK )
in R24,0x1
andi R24,248
cpi R24,40
breq L48
X17:
; return I2C_ERR;
clr R16
xjmp L44
L48:
; return I2C_CRR;
ldi R16,1
L44:
.dbline 0 ; func end
ret
; pRdDat -> R16,R17
.even
_I2C_RcvNAckDat::
; }
; /*--------------------------------------------------------------------
; 函數名稱:I2C接收數據且不產生應答
; 函數功能:
; 注意事項:
; 提示說明:
; 輸 入:
; 返 回:
; --------------------------------------------------------------------*/
; bool I2C_RcvNAckDat(uint8 *pRdDat)
; {
; I2CRcvNckByte();
ldi R24,132
out 0x36,R24
; I2CWaitAck();
L51:
L52:
in R2,0x36
sbrs R2,7
rjmp L51
X18:
; if( I2CChkAck()!=I2C_MR_DATA_NACK )
in R24,0x1
andi R24,248
cpi R24,88
breq L54
X19:
; return I2C_ERR;
clr R16
xjmp L50
L54:
; *pRdDat=TWDR;
in R2,0x3
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -