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

📄 ac15-4.lst

📁 AVR学习资料
💻 LST
📖 第 1 页 / 共 3 页
字号:
__text_start:
__start:
    003B E5CF      LDI	R28,0x5F
    003C E0D4      LDI	R29,4
    003D BFCD      OUT	0x3D,R28
    003E BFDE      OUT	0x3E,R29
    003F 51C0      SUBI	R28,0x10
    0040 40D0      SBCI	R29,0
    0041 EA0A      LDI	R16,0xAA
    0042 8308      STD	Y+0,R16
    0043 2400      CLR	R0
    0044 E6E0      LDI	R30,0x60
    0045 E0F0      LDI	R31,0
    0046 E010      LDI	R17,0
    0047 36E8      CPI	R30,0x68
    0048 07F1      CPC	R31,R17
    0049 F011      BEQ	0x004C
    004A 9201      ST	R0,Z+
    004B CFFB      RJMP	0x0047
    004C 8300      STD	Z+0,R16
    004D E7E6      LDI	R30,0x76
    004E E0F0      LDI	R31,0
    004F E6A0      LDI	R26,0x60
    0050 E0B0      LDI	R27,0
    0051 E010      LDI	R17,0
    0052 37E6      CPI	R30,0x76
    0053 07F1      CPC	R31,R17
    0054 F021      BEQ	0x0059
    0055 95C8      LPM
    0056 9631      ADIW	R30,1
    0057 920D      ST	R0,X+
    0058 CFF9      RJMP	0x0052
    0059 940E01A2  CALL	_main
_exit:
    005B CFFF      RJMP	_exit
_ePutstr:
  l                    --> R20
  i                    --> R22
  ptr                  --> R10
  y                    --> R12
  x                    --> R14
    005C 940E0399  CALL	push_gset5
    005E 2EC2      MOV	R12,R18
    005F 2EE0      MOV	R14,R16
    0060 9721      SBIW	R28,1
    0061 84AB      LDD	R10,Y+11
    0062 84BC      LDD	R11,Y+12
FILE: d:\MYDOCU~1\ac15-4\ac15-4.c
(0001) #include <iom16v.h>			
(0002) #include <macros.h>
(0003) //-----------------------------------------------
(0004) #define uchar unsigned char	
(0005) #define uint unsigned int
(0006) //-------------------引脚电平的宏定义---------
(0007) #define LCM_RS_1 PORTB|=BIT(PB0)	
(0008) #define LCM_RS_0 PORTB&=~BIT(PB0) 
(0009) #define LCM_RW_1 PORTB|=BIT(PB1)	
(0010) #define LCM_RW_0 PORTB&=~BIT(PB1) 
(0011) #define LCM_EN_1 PORTB|=BIT(PB2)	
(0012) #define LCM_EN_0 PORTB&=~BIT(PB2)  
(0013) #define LED_1 PORTB|=BIT(PB7)
(0014) #define LED_0 PORTB&=~BIT(PB7)
(0015) 
(0016) #define rd_device_add 0xa1
(0017) #define wr_device_add 0xa0
(0018) 
(0019) //======================================
(0020) //TWI状态定义
(0021) //MT 主方式传输  MR 主方式接收
(0022) #define START 0x08 
(0023) #define RE_START 0x10
(0024) #define MT_SLA_ACK 0x18
(0025) #define MT_SLA_NOACK 0x20
(0026) #define MT_DATA_ACK  0x28
(0027) #define MT_DATA_NOACK 0x30
(0028) #define MR_SLA_ACK  0x40
(0029) #define MR_SLA_NOACK 0x48
(0030) #define MR_DATA_ACK 0x50
(0031) #define MR_DATA_NOACK 0x58
(0032) 
(0033) //常用TWI操作(主模式写和主模式读)
(0034) #define Start()    	  (TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN))
(0035) #define Stop()     	  (TWCR=(1<<TWINT)|(1<<TWSTO)|(1<<TWEN))
(0036) #define Wait()	   	  {while(!(TWCR&(1<<TWINT)));}
(0037) #define TestAck() 	  (TWSR&0xf8)
(0038) #define SetAck()	  (TWCR|=(1<<TWEA))
(0039) #define SetNoAck()    (TWCR&=~(1<<TWEA))
(0040) #define Twi()	  	  (TWCR=(1<<TWINT)|(1<<TWEN))
(0041) #define Write8Bit(x)  {TWDR=(x);TWCR=(1<<TWINT)|(1<<TWEN);} 
(0042) 
(0043) #define DataPort PORTA		
(0044) #define Busy 0x80			
(0045) #define xtal 8   		
(0046) 
(0047) //======================================
(0048) const uchar str0[]={"-Time   :  :  --"};//待显字符串
(0049) const uchar str1[]={"-ATime   :  : --"};//待显字符串
(0050) 
(0051) //========函数声明=========
(0052) void WaitForEnable(void);
(0053) void LcdWriteData(uchar W);
(0054) void LcdWriteCommand(uchar CMD,uchar Attribc);
(0055) void InitLcd(void);
(0056) void Display(uchar dd);
(0057) void DisplayOneChar(uchar x,uchar y,uchar Wdata);
(0058) void ePutstr(uchar x,uchar y,uchar const *ptr);
(0059) void port_init(void);
(0060) void delay_ms(unsigned int time);
(0061) void delay_us(int time);
(0062) void init_devices(void);
(0063) 
(0064) //**********************显示指定座标的一串字符子函数**************
(0065) void ePutstr(uchar x,uchar y,uchar const *ptr)
(0066) {
(0067) uchar i,l=0;
    0063 2744      CLR	R20
    0064 C001      RJMP	0x0066
(0068) 	while(ptr[l]>31){l++;}
    0065 9543      INC	R20
    0066 2FE4      MOV	R30,R20
    0067 27FF      CLR	R31
    0068 0DEA      ADD	R30,R10
    0069 1DFB      ADC	R31,R11
    006A 91E4      LPM	R30,0(Z)
    006B E18F      LDI	R24,0x1F
    006C 178E      CP	R24,R30
    006D F3B8      BCS	0x0065
(0069) 	for(i=0;i<l;i++){
    006E 2766      CLR	R22
    006F C014      RJMP	0x0084
(0070) 	DisplayOneChar(x++,y,ptr[i]);
    0070 2FE6      MOV	R30,R22
    0071 27FF      CLR	R31
    0072 0DEA      ADD	R30,R10
    0073 1DFB      ADC	R31,R11
    0074 91E4      LPM	R30,0(Z)
    0075 83E8      STD	Y+0,R30
    0076 2D2C      MOV	R18,R12
    0077 2C2E      MOV	R2,R14
    0078 2D82      MOV	R24,R2
    0079 5F8F      SUBI	R24,0xFF
    007A 2EE8      MOV	R14,R24
    007B 2D02      MOV	R16,R2
    007C D01E      RCALL	_DisplayOneChar
(0071) 	if(x==16){
    007D 2D8E      MOV	R24,R14
    007E 3180      CPI	R24,0x10
    007F F419      BNE	0x0083
(0072) 		x=0;y^=1;
    0080 24EE      CLR	R14
    0081 E081      LDI	R24,1
    0082 26C8      EOR	R12,R24
    0083 9563      INC	R22
    0084 1764      CP	R22,R20
    0085 F350      BCS	0x0070
    0086 9621      ADIW	R28,1
    0087 940E0396  CALL	pop_gset5
    0089 9508      RET
_LocateXY:
  temp                 --> R20
  posy                 --> R22
  posx                 --> R10
    008A 940E039D  CALL	push_gset3
    008C 2F62      MOV	R22,R18
    008D 2EA0      MOV	R10,R16
(0073) 	}
(0074)   }
(0075) }
(0076) 
(0077) //*******************显示光标定位子函数******************
(0078) void LocateXY(char posx,char posy)
(0079) {
(0080) uchar temp;
(0081) 	temp&=0x7f;
    008E 774F      ANDI	R20,0x7F
(0082) 	temp=posx&0x0f;
    008F 2D4A      MOV	R20,R10
    0090 704F      ANDI	R20,0xF
(0083) 	posy&=0x01;
    0091 7061      ANDI	R22,1
(0084) 	if(posy)temp|=0x40;
    0092 F009      BEQ	0x0094
    0093 6440      ORI	R20,0x40
(0085) 	temp|=0x80;
    0094 6840      ORI	R20,0x80
(0086) 	LcdWriteCommand(temp,0);
    0095 2722      CLR	R18
    0096 2F04      MOV	R16,R20
    0097 D031      RCALL	_LcdWriteCommand
    0098 940E0393  CALL	pop_gset3
    009A 9508      RET
_DisplayOneChar:
  Wdata                --> Y+4
  y                    --> R22
  x                    --> R20
    009B 940E039F  CALL	push_gset2
    009D 2F62      MOV	R22,R18
    009E 2F40      MOV	R20,R16
(0087) }
(0088) 
(0089) //*******************显示指定座标的一个字符子函数*******************
(0090) void DisplayOneChar(uchar x,uchar y,uchar Wdata)
(0091) {
(0092) LocateXY(x,y);
    009F 2F26      MOV	R18,R22
    00A0 2F04      MOV	R16,R20
    00A1 DFE8      RCALL	_LocateXY
(0093) LcdWriteData(Wdata);
    00A2 810C      LDD	R16,Y+4
    00A3 D038      RCALL	_LcdWriteData
    00A4 940E0390  CALL	pop_gset2
    00A6 9508      RET
(0094) }
(0095) 
(0096) //*******************LCD初始化子函数*********************
(0097) void InitLcd(void) 
(0098) {
(0099) LcdWriteCommand(0x38,0); 
_InitLcd:
    00A7 2722      CLR	R18
    00A8 E308      LDI	R16,0x38
    00A9 D01F      RCALL	_LcdWriteCommand
(0100) delay_ms(5);
    00AA E005      LDI	R16,5
    00AB E010      LDI	R17,0
    00AC D2B4      RCALL	_delay_ms
(0101) LcdWriteCommand(0x38,0); 
    00AD 2722      CLR	R18
    00AE E308      LDI	R16,0x38
    00AF D019      RCALL	_LcdWriteCommand
(0102) delay_ms(5);
    00B0 E005      LDI	R16,5
    00B1 E010      LDI	R17,0
    00B2 D2AE      RCALL	_delay_ms
(0103) LcdWriteCommand(0x38,0);
    00B3 2722      CLR	R18
    00B4 E308      LDI	R16,0x38
    00B5 D013      RCALL	_LcdWriteCommand
(0104) delay_ms(5);
    00B6 E005      LDI	R16,5
    00B7 E010      LDI	R17,0
    00B8 D2A8      RCALL	_delay_ms
(0105) LcdWriteCommand(0x38,1); 
    00B9 E021      LDI	R18,1
    00BA E308      LDI	R16,0x38
    00BB D00D      RCALL	_LcdWriteCommand
(0106) LcdWriteCommand(0x08,1); 
    00BC E021      LDI	R18,1
    00BD E008      LDI	R16,0x8
    00BE D00A      RCALL	_LcdWriteCommand
(0107) LcdWriteCommand(0x01,1); 
    00BF E021      LDI	R18,1
    00C0 E001      LDI	R16,1
    00C1 D007      RCALL	_LcdWriteCommand
(0108) LcdWriteCommand(0x06,1); 
    00C2 E021      LDI	R18,1
    00C3 E006      LDI	R16,6
    00C4 D004      RCALL	_LcdWriteCommand
(0109) LcdWriteCommand(0x0c,1); 
    00C5 E021      LDI	R18,1
    00C6 E00C      LDI	R16,0xC
    00C7 D001      RCALL	_LcdWriteCommand
    00C8 9508      RET
_LcdWriteCommand:
  Attribc              --> R22
  CMD                  --> R20
    00C9 940E039F  CALL	push_gset2
    00CB 2F62      MOV	R22,R18
    00CC 2F40      MOV	R20,R16
(0110) }
(0111) 
(0112) //********************写命令到LCM子函数********************
(0113) void LcdWriteCommand(uchar CMD,uchar Attribc)
(0114) {
(0115) if(Attribc)WaitForEnable();
    00CD 2366      TST	R22
    00CE F009      BEQ	0x00D0
    00CF D01C      RCALL	_WaitForEnable
(0116) LCM_RS_0;LCM_RW_0;_NOP();
    00D0 98C0      CBI	0x18,0
    00D1 98C1      CBI	0x18,1
    00D2 0000      NOP
(0117) DataPort=CMD;_NOP();
    00D3 BB4B      OUT	0x1B,R20
    00D4 0000      NOP
(0118) LCM_EN_1;_NOP();_NOP();LCM_EN_0;
    00D5 9AC2      SBI	0x18,2
    00D6 0000      NOP
    00D7 0000      NOP
    00D8 98C2      CBI	0x18,2
    00D9 940E0390  CALL	pop_gset2
    00DB 9508      RET
_LcdWriteData:
  dataW                --> R20
    00DC 940E03A1  CALL	push_gset1
    00DE 2F40      MOV	R20,R16
(0119) }
(0120) 
(0121) //*******************写数据到LCM子函数********************
(0122) void LcdWriteData(uchar dataW)
(0123) {
(0124) WaitForEnable();
    00DF D00C      RCALL	_WaitForEnable
(0125) LCM_RS_1;LCM_RW_0;_NOP();
    00E0 9AC0      SBI	0x18,0
    00E1 98C1      CBI	0x18,1
    00E2 0000      NOP
(0126) DataPort=dataW;_NOP();
    00E3 BB4B      OUT	0x1B,R20
    00E4 0000      NOP
(0127) LCM_EN_1;_NOP();_NOP();LCM_EN_0;
    00E5 9AC2      SBI	0x18,2
    00E6 0000      NOP
    00E7 0000      NOP
    00E8 98C2      CBI	0x18,2
    00E9 940E03A4  CALL	pop_gset1
    00EB 9508      RET
(0128) }
(0129) 
(0130) //*******************检测LCD忙信号子函数*********************
(0131) void WaitForEnable(void)
(0132) {
(0133) uchar val;
(0134) DataPort=0xff;
_WaitForEnable:
  val                  --> R16
    00EC EF8F      LDI	R24,0xFF
    00ED BB8B      OUT	0x1B,R24
(0135) LCM_RS_0;LCM_RW_1;_NOP();
    00EE 98C0      CBI	0x18,0
    00EF 9AC1      SBI	0x18,1
    00F0 0000      NOP
(0136) LCM_EN_1;_NOP();_NOP();
    00F1 9AC2      SBI	0x18,2
    00F2 0000      NOP
    00F3 0000      NOP
(0137) DDRA=0x00;
    00F4 2422      CLR	R2
    00F5 BA2A      OUT	0x1A,R2
(0138) val=PINA;
    00F6 B309      IN	R16,0x19
    00F7 C001      RJMP	0x00F9
(0139) while(val&Busy)val=PINA;
    00F8 B309      IN	R16,0x19
    00F9 FD07      SBRC	R16,7
    00FA CFFD      RJMP	0x00F8
(0140) LCM_EN_0;
    00FB 98C2      CBI	0x18,2
(0141) DDRA=0xff;
    00FC EF8F      LDI	R24,0xFF
    00FD BB8A      OUT	0x1A,R24
    00FE 9508      RET
(0142) }
(0143) 
(0144) /******************定义结构体变量time1,time2********************/
(0145) struct date
(0146) {
(0147) uchar hour;
(0148) uchar min;
(0149) uchar sec;
(0150) uchar dida;
(0151) }time1,time2;
(0152) 
(0153) /******************端口初始化**********************/
(0154) void port_init(void)
(0155) {
(0156)  PORTA = 0x00;
_port_init:
    00FF 2422      CLR	R2
    0100 BA2B      OUT	0x1B,R2
(0157)  DDRA  = 0xFF;
    0101 EF8F      LDI	R24,0xFF
    0102 BB8A      OUT	0x1A,R24
(0158)  PORTB = 0x00;
    0103 BA28      OUT	0x18,R2
(0159)  DDRB  = 0xFF;
    0104 BB87      OUT	0x17,R24
(0160)  PORTC = 0x00; 
    0105 BA25      OUT	0x15,R2
(0161)  DDRC  = 0x03;
    0106 E083      LDI	R24,3
    0107 BB84      OUT	0x14,R24
(0162)  PORTD = 0xFF;
    0108 EF8F      LDI	R24,0xFF
    0109 BB82      OUT	0x12,R24
(0163)  DDRD  = 0x00;
    010A BA21      OUT	0x11,R2
    010B 9508      RET
(0164) }
(0165) 
(0166) /*****************扫描按键*****************/
(0167) uchar scan_key(void)		
(0168) {					
(0169) uchar temp;			
(0170) temp=PIND;				
_scan_key:
  temp                 --> R16
    010C B300      IN	R16,0x10
(0171) return temp;			
    010D 9508      RET
_i2c_Read:
  temp                 --> R20
  RomAddress           --> R16
    010E 940E03A1  CALL	push_gset1
(0172) }					
(0173) 
(0174) /******************************************
(0175)                I2C总线读一个字节

⌨️ 快捷键说明

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