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

📄 text2.lst

📁 ATmega16-ad1602
💻 LST
📖 第 1 页 / 共 4 页
字号:
(0092) 			while((PINA&0x08)==0)
(0093) 	    	{
(0094) 			key_press_num++;
    00137 9563      INC	R22
(0095) 			delay_nms(10);           //10x200=2000ms=2s 
    00138 E00A      LDI	R16,0xA
    00139 E010      LDI	R17,0
    0013A DF0C      RCALL	_delay_nms
(0096)             //****************************长按键模式开始************************
(0097) 			
(0098) 			if(key_press_num==100) //大约2s,进入长按键模式
    0013B 3664      CPI	R22,0x64
    0013C F471      BNE	0x014B
(0099) 			 {
(0100) 				key_press_num=0; 
    0013D 2766      CLR	R22
    0013E C00A      RJMP	0x0149
(0101) 				while((PINA&0x08)==0)  //这里用于识别是否按键还在按下,如果按下执行相关动作,否则退出
(0102) 				{
(0103) 				if(num>0)    	//是否达到最大值
    0013F 3040      CPI	R20,0
    00140 0745      CPC	R20,R21
    00141 F011      BEQ	0x0144
(0104) 				 num=num-24;		  	//未到达最大值则加操作
    00142 5148      SUBI	R20,0x18
    00143 4050      SBCI	R21,0
(0105) 										//即时把显示数据处理,如果去掉下面2
(0106)                 						//句处理信息,实际上看不到渐变效果,
(0107)                		        			//而是看到跳变效果
(0108) 										//用户可以自行屏蔽测试
(0109)      									//分解显示信息,如要显示68,则68/10=6  68%10=8
(0110) 				spi_tlc5615(num);  
    00144 018A      MOVW	R16,R20
    00145 D01C      RCALL	_spi_tlc5615
(0111) 				delay_nms(30);	//用于调节长按循环操作的速度,可以自行调整此值以便达到最佳效果
    00146 E10E      LDI	R16,0x1E
    00147 E010      LDI	R17,0
    00148 DEFE      RCALL	_delay_nms
    00149 9BCB      SBIS	0x19,3
    0014A CFF4      RJMP	0x013F
    0014B 9BCB      SBIS	0x19,3
    0014C CFEA      RJMP	0x0137
(0112) 				}
(0113) 			  }
(0114) 		     }
(0115) 			 key_press_num=0;//防止累加造成错误识别
    0014D 2766      CLR	R22
(0116) 			 
(0117)              //****************************长按键模式结束***********************
(0118) 			 
(0119) 			 if(num>0)
    0014E 3040      CPI	R20,0
    0014F 0745      CPC	R20,R21
    00150 F011      BEQ	0x0153
(0120) 			 num=num-24;
    00151 5148      SUBI	R20,0x18
    00152 4050      SBCI	R21,0
(0121) 			 spi_tlc5615(num);
    00153 018A      MOVW	R16,R20
    00154 D00D      RCALL	_spi_tlc5615
    00155 CFA5      RJMP	0x00FB
    00156 9622      ADIW	R28,2
    00157 9508      RET
FILE: F:\file\数控电源3\ad_da\text\spi_tlc5615.c
(0001) #define SPI_TLC5615_C
(0002) #include "includes.h"
(0003) void spi_init(void)//SPI初始化
(0004) {
(0005) 	SPCR=0X50; //使能SPI,MSB先发,主模式,CPOL为0,默认4分频
_spi_init:
    00158 E580      LDI	R24,0x50
    00159 B98D      OUT	0x0D,R24
    0015A 9508      RET
(0006) 	
(0007) }
(0008) void spi_io_init(void)
(0009) {
(0010) 	DDRB|=(1<<PB4)|(1<<PB5)|(1<<PB7); //PB4-SS,PB5-MOSI,PB7-SCK
_spi_io_init:
    0015B B387      IN	R24,0x17
    0015C 6B80      ORI	R24,0xB0
    0015D BB87      OUT	0x17,R24
(0011) 	PORTB|=(1<<PB4)|(1<<PB5)|(1<<PB7);//PB4拉高TLC5615不使能;MOSI,SCK为高电平
    0015E B388      IN	R24,0x18
    0015F 6B80      ORI	R24,0xB0
    00160 BB88      OUT	0x18,R24
    00161 9508      RET
_spi_tlc5615:
  temp                 --> R22
  temp2                --> R10
  temp1                --> R12
  status               --> R20
  idata                --> R20
    00162 D17B      RCALL	push_xgsetF03C
    00163 01A8      MOVW	R20,R16
(0012) }
(0013) void spi_tlc5615(unsigned int idata)//0000 00(78 8765 4321)
(0014) {
(0015) 	unsigned int temp;
(0016) 	unsigned char temp1=0,temp2=0,status;
(0017) 	temp=idata<<2;//0000 7887 6543 2100
    00164 01BA      MOVW	R22,R20
    00165 0F66      LSL	R22
    00166 1F77      ROL	R23
    00167 0F66      LSL	R22
    00168 1F77      ROL	R23
(0018) 	temp1=(temp&0xff00)>>8;//0000 0000 (0000 7887) 
    00169 01CB      MOVW	R24,R22
    0016A 7080      ANDI	R24,0
    0016B 016C      MOVW	R12,R24
    0016C 2CCD      MOV	R12,R13
    0016D 24DD      CLR	R13
(0019) 	temp2=(idata&0x00ff);//0000 0000 (6543 2100)
    0016E 01CA      MOVW	R24,R20
    0016F 7090      ANDI	R25,0
    00170 2EA8      MOV	R10,R24
(0020) 	
(0021) 	PORTB&=~(1<<PB4);//使能TLC5615
    00171 98C4      CBI	0x18,4
(0022) 	SPDR=temp1;//传送数据高二位
    00172 B8CF      OUT	0x0F,R12
(0023) 	do	
(0024) 	{
(0025) 	  status=SPSR;
    00173 B14E      IN	R20,0x0E
(0026) 	}while(!(status&=0X80));
    00174 2F84      MOV	R24,R20
    00175 7880      ANDI	R24,0x80
    00176 2F48      MOV	R20,R24
    00177 2388      TST	R24
    00178 F3D1      BEQ	0x0173
(0027) 	
(0028) 	delay_nms(10);
    00179 E00A      LDI	R16,0xA
    0017A E010      LDI	R17,0
    0017B DECB      RCALL	_delay_nms
(0029) 	
(0030) 	SPSR=0;
    0017C 2422      CLR	R2
    0017D B82E      OUT	0x0E,R2
(0031) 	SPDR=temp2;//传送数据低八位
    0017E B8AF      OUT	0x0F,R10
(0032) 	do
(0033) 	{
(0034) 	  status=SPSR;
    0017F B14E      IN	R20,0x0E
(0035) 	}while(!(status&=0X80));
    00180 2F84      MOV	R24,R20
    00181 7880      ANDI	R24,0x80
    00182 2F48      MOV	R20,R24
    00183 2388      TST	R24
    00184 F3D1      BEQ	0x017F
(0036) 	SPSR=0;
    00185 2422      CLR	R2
    00186 B82E      OUT	0x0E,R2
(0037) 	delay_nms(10);
    00187 E00A      LDI	R16,0xA
    00188 E010      LDI	R17,0
    00189 DEBD      RCALL	_delay_nms
(0038) 	PORTB|=(1<<PB4);//TLC5615不使能
    0018A 9AC4      SBI	0x18,4
    0018B C15B      RJMP	pop_xgsetF03C
FILE: F:\file\数控电源3\ad_da\text\LCD.c
(0001) // ************************************************
(0002) // *** 采用4位数据线的1602液晶驱动程序 ***
(0003) // *** LCD.C ***
(0004) // ************************************************
(0005) #define ENABLE_BIT_DEFINITIONS
(0006) #define LCD_C
(0007) #include "includes.h"
(0008) // ***** Define I/O pins ***** //
(0009) #define BIT7 0x80
(0010) #define BIT6 0x40
(0011) #define BIT5 0x20
(0012) #define BIT4 0x10
(0013) #define BIT3 0x08
(0014) #define BIT2 0x04
(0015) #define BIT1 0x02
(0016) #define BIT0 0x01
(0017) // *** Set port for LCD Data Bus 8 bit mode *** //
(0018) #define LCD_OP_PORT PORTC
(0019) #define LCD_IP_PORT PINC
(0020) #define LCD_DIR_PORT DDRC
(0021) // *** Set LCD Enable Port and Bit values *** //
(0022) //#define LCD_EN LCD_OP_PORT.2
(0023) // *** Set LCD Register Select Port and Bit values *** //
(0024) //#define LCD_RS LCD_OP_PORT.0
(0025) // *** Set LCD Read/Write Port and Bit values *** //
(0026) //#define LCD_RW LCD_OP_PORT.1
(0027) /****************************************************************/
(0028)  
(0029)  #define LCD_EN  (1 << 2)     //引脚定义
(0030)  #define LCD_RS (1 << 0)
(0031)  #define LCD_RW (1 << 1)
(0032)  
(0033)  #define lcd_set_e()  (LCD_OP_PORT |= LCD_EN)   //置位与清零
(0034)  #define lcd_set_rs() (LCD_OP_PORT |= LCD_RS)
(0035)  #define lcd_set_rw() (LCD_OP_PORT |= LCD_RW)
(0036)  #define lcd_clear_e()  (LCD_OP_PORT &= ~LCD_EN)
(0037)  #define lcd_clear_rs() (LCD_OP_PORT &= ~LCD_RS)
(0038)  #define lcd_clear_rw() (LCD_OP_PORT &= ~LCD_RW)
(0039) /****************************************************************/
(0040) 
(0041) #define LCD_ON 0x0C
(0042) #define LCD_CURS_ON 0x0D
(0043) #define LCD_OFF 0x08
(0044) #define LCD_HOME 0x02
(0045) #define LCD_CLEAR 0x01
(0046) #define LCD_NEW_LINE 0xC0
(0047) #define LCD_FUNCTION_SET 0x28
(0048) #define LCD_MODE_SET 0x06
(0049) 
(0050) 
(0051) void LCD_INIT(void)
(0052) {
(0053) LCD_DIR_PORT = 0xff; // LCD port output
_LCD_INIT:
    0018C EF8F      LDI	R24,0xFF
    0018D BB84      OUT	0x14,R24
(0054) LCD_OP_PORT = 0x30; // Load high-data to port
    0018E E380      LDI	R24,0x30
    0018F BB85      OUT	0x15,R24
(0055) lcd_clear_rw(); // Set LCD to write
    00190 98A9      CBI	0x15,1
(0056) lcd_clear_rs(); // Set LCD to command
    00191 98A8      CBI	0x15,0
(0057) lcd_set_e(); // Write data to LCD
    00192 9AAA      SBI	0x15,2
(0058) asm("nop");
    00193 0000      NOP
(0059) asm("nop");
    00194 0000      NOP
(0060) lcd_clear_e(); // Disable LCD
    00195 98AA      CBI	0x15,2
(0061) delay_nus(40);
    00196 E208      LDI	R16,0x28
    00197 E010      LDI	R17,0
    00198 DE97      RCALL	_delay_nus
(0062) lcd_clear_rw() ; // Set LCD to write
    00199 98A9      CBI	0x15,1
(0063) lcd_clear_rs(); // Set LCD to command
    0019A 98A8      CBI	0x15,0
(0064) lcd_set_e(); // Write data to LCD
    0019B 9AAA      SBI	0x15,2
(0065) asm("nop");
    0019C 0000      NOP
(0066) asm("nop");
    0019D 0000      NOP
(0067) lcd_clear_e(); // Disable LCD
    0019E 98AA      CBI	0x15,2
(0068) delay_nus(40);
    0019F E208      LDI	R16,0x28
    001A0 E010      LDI	R17,0
    001A1 DE8E      RCALL	_delay_nus
(0069) lcd_set_e(); // Write data to LCD
    001A2 9AAA      SBI	0x15,2
(0070) asm("nop");
    001A3 0000      NOP
(0071) asm("nop");
    001A4 0000      NOP
(0072) lcd_clear_e(); // Disable LCD
    001A5 98AA      CBI	0x15,2
(0073) delay_nus(40);
    001A6 E208      LDI	R16,0x28
    001A7 E010      LDI	R17,0
    001A8 DE87      RCALL	_delay_nus
(0074) LCD_OP_PORT = 0x20;
    001A9 E280      LDI	R24,0x20
    001AA BB85      OUT	0x15,R24
(0075) lcd_set_e(); // Write data to LCD
    001AB 9AAA      SBI	0x15,2
(0076) asm("nop");
    001AC 0000      NOP
(0077) asm("nop");
    001AD 0000      NOP
(0078) lcd_clear_e(); // Disable LCD
    001AE 98AA      CBI	0x15,2
(0079) delay_nus(40);
    001AF E208      LDI	R16,0x28
    001B0 E010      LDI	R17,0
    001B1 CE7E      RJMP	_delay_nus
_LCD_Busy:
  low                  --> R12
  high                 --> R10
  temp                 --> R20
    001B2 D11D      RCALL	push_xgset303C
(0080) }
(0081) //*****************************************************//
(0082) // This routine will return the busy flag from the LCD //
(0083) //*****************************************************//
(0084) void LCD_Busy ( void )
(0085) {
(0086) unsigned char temp,high;
(0087) unsigned char low;
(0088) LCD_DIR_PORT = 0x0f; // Make I/O Port input
    001B3 E08F      LDI	R24,0xF
    001B4 BB84      OUT	0x14,R24
(0089) do
(0090) {
(0091) temp=LCD_OP_PORT;
    001B5 B345      IN	R20,0x15
(0092) temp=temp&BIT3;
    001B6 7048      ANDI	R20,0x8
(0093) LCD_OP_PORT=temp;
    001B7 BB45      OUT	0x15,R20
(0094) lcd_set_rw(); // Set LCD to READ
    001B8 9AA9      SBI	0x15,1
(0095) lcd_clear_rs();
    001B9 98A8      CBI	0x15,0
(0096) lcd_set_e();
    001BA 9AAA      SBI	0x15,2
(0097) delay_nus(3);
    001BB E003      LDI	R16,3
    001BC E010      LDI	R17,0
    001BD DE72      RCALL	_delay_nus
(0098) high = LCD_IP_PORT; // read the high nibble.
    001BE B2A3      IN	R10,0x13
(0099) lcd_clear_e(); // Disable LCD
    001BF 98AA      CBI	0x15,2
(0100) lcd_set_e();
    001C0 9AAA      SBI	0x15,2
(0101) asm("nop");
    001C1 0000      NOP
(0102) asm("nop");
    001C2 0000      NOP
(0103) low = LCD_IP_PORT; // read the low nibble.
    001C3 B2C3      IN	R12,0x13
(0104) lcd_clear_e(); // Disable LCD
    001C4 98AA      CBI	0x15,2
(0105) } while(high & 0x80);
    001C5 FCA7      SBRC	R10,7
    001C6 CFEE      RJMP	0x01B5
(0106) delay_nus(20);
    001C7 E104      LDI	R16,0x14
    001C8 E010      LDI	R17,0
    001C9 DE66      RCALL	_delay_nus
    001CA C10C      RJMP	pop_xgset303C
_LCD_WriteControl:
  temp                 --> R20
  CMD                  --> R22
    001CB 934A      ST	-Y,R20
    001CC 936A      ST	-Y,R22
    001CD 2F60      MOV	R22,R16
(0107) }
(0108) // ********************************************** //
(0109) // *** Write a control instruction to the LCD *** //
(0110) // ********************************************** //
(0111) void LCD_WriteControl (unsigned char CMD)
(0112) {
(0113) char temp;
(0114) LCD_Busy(); // Test if LCD busy
    001CE DFE3      RCALL	_LCD_Busy
(0115) LCD_DIR_PORT = 0xff; // LCD port output
    001CF EF8F      LDI	R24,0xFF
    001D0 BB84      OUT	0x14,R24
(0116) temp=LCD_OP_PORT;
    001D1 B345      IN	R20,0x15
(0117) temp=temp&BIT3;
    001D2 7048      ANDI	R20,0x8
(0118) LCD_OP_PORT =(CMD & 0xf0)|temp; // Load high-data to port
    001D3 2F86      MOV	R24,R22
    001D4 7F80      ANDI	R24,0xF0
    001D5 2B84      OR	R24,R20
    001D6 BB85      OUT	0x15,R24
(0119) lcd_clear_rw(); // Set LCD to write
    001D7 98A9      CBI	0x15,1
(0120) lcd_clear_rs(); // Set LCD to command
    001D8 98A8      CBI	0x15,0
(0121) lcd_set_e(); // Write data to LCD
    001D9 9AAA      SBI	0x15,2
(0122) asm("nop");
    001DA 0000      NOP
(0123) asm("nop");
    001DB 0000      NOP
(0124) lcd_clear_e(); // Disable LCD
    001DC 98AA      CBI	0x15,2
(0125) LCD_OP_PORT =(CMD<<4)|temp; // Load low-data to port
    001DD 2F86      MOV	R24,R22
    001DE 708F      ANDI	R24,0xF
    001DF 9582      SWAP	R24
    001E0 2B84      OR	R24,R20
    001E1 BB85      OUT	0x15,R24
(0126) lcd_clear_rw(); // Set LCD to write
    001E2 98A9      CBI	0x15,1
(0127) lcd_clear_rs(); // Set LCD to command
    001E3 98A8      CBI	0x15,0
(0128) lcd_set_e(); // Write data to LCD
    001E4 9AAA      SBI	0x15,2
(0129) asm("nop");
    001E5 0000      NOP
(0130) asm("nop");
    001E6 0000      NOP
(0131) lcd_clear_e(); // Disable LCD
    001E7 98AA      CBI	0x15,2
    001E8 9169      LD	R22,Y+
    001E9 9149      LD	R20,Y+
    001EA 9508      RET
_LCD_WriteData:
  temp                 --> R20
  Data                 --> R22
    001EB 934A      ST	-Y,R20
    001EC 936A      ST	-Y,R22
    001ED 2F60      MOV	R22,R16
(0132) }
(0133) // ***************************************** //
(0134) // *** Write one byte of data to the LCD *** //
(0135) // ***************************************** //
(0136) void LCD_WriteData (unsigned char Data)
(0137) {
(0138) char temp;
(0139) LCD_Busy(); // Test if LCD Busy
    001EE DFC3      RCALL	_LCD_Busy
(0140) LCD_DIR_PORT = 0xFF; // LCD port output
    001EF EF8F      LDI	R24,0xFF
    001F0 BB84      OUT	0x14,R24
(0141) temp=LCD_OP_PORT;
    001F1 B345      IN	R20,0x15
(0142) temp=temp&BIT3;
    001F2 7048      ANDI	R20,0x8
(0143) LCD_OP_PORT =(Data & 0xf0)|temp; // Load high-data to port
    001F3 2F86      MOV	R24,R22
    001F4 7F80      ANDI	R24,0xF0
    001F5 2B84      OR	R24,R20
    001F6 BB85      OUT	0x15,R24
(0144) lcd_clear_rw() ; // Set LCD to write
    001F7 98A9      CBI	0x15,1
(0145) lcd_set_rs(); // Set LCD to data
    001F8 9AA8      SBI	0x15,0
(0146) lcd_set_e(); // Write data to LCD
    001F9 9AAA      SBI	0x15,2
(0147) asm("nop");
    001FA 0000      NOP
(0148) asm("nop");
    001FB 0000      NOP
(0149) lcd_clear_e(); // Disable LCD
    001FC 98AA      CBI	0x15,2
(0150) LCD_OP_PORT = (Data << 4)|temp; // Load low-data to port
    001FD 2F86      MOV	R24,R22
    001FE 708F      ANDI	R24,0xF
    001FF 9582      SWAP	R24
    00200 2B84      OR	R24,R20
    00201 BB85      OUT	0x15,R24
(0151) lcd_clear_rw() ; // Set LCD to write
    00202 98A9      CBI	0x15,1
(0152) lcd_set_rs(); // Set LCD to data
    00203 9AA8      SBI	0x15,0

⌨️ 快捷键说明

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