📄 pwm.lst
字号:
013A D141 RCALL push_gset2
013B 01B8 MOVW R22,R16
(0008)
(0009) void delay_nus(unsigned int n) //N us延时函数
(0010) {
(0011) unsigned int i=0;
013C 2744 CLR R20
013D 2755 CLR R21
(0012) for (i=0;i<n;i++)
013E C003 RJMP 0x0142
(0013) delay_1us();
013F DFF8 RCALL _delay_1us
0140 5F4F SUBI R20,0xFF
0141 4F5F SBCI R21,0xFF
0142 1746 CP R20,R22
0143 0757 CPC R21,R23
0144 F3D0 BCS 0x013F
(0014) }
0145 D11B RCALL pop_gset2
0146 9508 RET
(0015)
(0016) void delay_1ms(void) //1ms延时函数
(0017) {
(0018) unsigned int i;
(0019) for (i=0;i<(unsigned int)(XTAL*143-2);i++);
_delay_1ms:
i --> R16
0147 2700 CLR R16
0148 2711 CLR R17
0149 C002 RJMP 0x014C
014A 5F0F SUBI R16,0xFF
014B 4F1F SBCI R17,0xFF
014C 330A CPI R16,0x3A
014D E0E2 LDI R30,2
014E 071E CPC R17,R30
014F F3D0 BCS 0x014A
(0020) }
0150 9508 RET
_delay_nms:
i --> R20
n --> R22
0151 D12A RCALL push_gset2
0152 01B8 MOVW R22,R16
(0021)
(0022) void delay_nms(unsigned int n) //N ms延时函数
(0023) {
(0024) unsigned int i=0;
0153 2744 CLR R20
0154 2755 CLR R21
(0025) for (i=0;i<n;i++)
0155 C003 RJMP 0x0159
(0026) {
(0027) delay_1ms();
0156 DFF0 RCALL _delay_1ms
0157 5F4F SUBI R20,0xFF
0158 4F5F SBCI R21,0xFF
0159 1746 CP R20,R22
015A 0757 CPC R21,R23
015B F3D0 BCS 0x0156
(0028) }
(0029) }
015C D104 RCALL pop_gset2
015D 9508 RET
FILE: D:\NEW\AVR_PWM\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 PORTB
(0019) #define LCD_IP_PORT PINB
(0020) #define LCD_DIR_PORT DDRB
(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:
015E EF8F LDI R24,0xFF
015F BB87 OUT 0x17,R24
(0054) LCD_OP_PORT = 0x30; // Load high-data to port
0160 E380 LDI R24,0x30
0161 BB88 OUT 0x18,R24
(0055) lcd_clear_rw(); // Set LCD to write
0162 98C1 CBI 0x18,1
(0056) lcd_clear_rs(); // Set LCD to command
0163 98C0 CBI 0x18,0
0164 940E0282 CALL <created procedures>
(0057) lcd_set_e(); // Write data to LCD
(0058) asm("nop");
(0059) asm("nop");
(0060) lcd_clear_e(); // Disable LCD
(0061) delay_nus(40);
0166 E208 LDI R16,0x28
0167 E010 LDI R17,0
0168 DFD1 RCALL _delay_nus
(0062) lcd_clear_rw() ; // Set LCD to write
0169 98C1 CBI 0x18,1
(0063) lcd_clear_rs(); // Set LCD to command
016A 98C0 CBI 0x18,0
016B 940E0282 CALL <created procedures>
(0064) lcd_set_e(); // Write data to LCD
(0065) asm("nop");
(0066) asm("nop");
(0067) lcd_clear_e(); // Disable LCD
(0068) delay_nus(40);
016D E208 LDI R16,0x28
016E E010 LDI R17,0
016F DFCA RCALL _delay_nus
0170 940E0282 CALL <created procedures>
(0069) lcd_set_e(); // Write data to LCD
(0070) asm("nop");
(0071) asm("nop");
(0072) lcd_clear_e(); // Disable LCD
(0073) delay_nus(40);
0172 E208 LDI R16,0x28
0173 E010 LDI R17,0
0174 DFC5 RCALL _delay_nus
(0074) LCD_OP_PORT = 0x20;
0175 E280 LDI R24,0x20
0176 BB88 OUT 0x18,R24
0177 940E0282 CALL <created procedures>
(0075) lcd_set_e(); // Write data to LCD
(0076) asm("nop");
(0077) asm("nop");
(0078) lcd_clear_e(); // Disable LCD
(0079) delay_nus(40);
0179 E208 LDI R16,0x28
017A E010 LDI R17,0
(0080) }
017B CFBE RJMP _delay_nus
_LCD_Busy:
low --> R20
high --> R22
temp --> R10
017C D102 RCALL push_gset3
(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
017D E08F LDI R24,0xF
017E BB87 OUT 0x17,R24
(0089) do
(0090) {
(0091) temp=LCD_OP_PORT;
017F B2A8 IN R10,0x18
(0092) temp=temp&BIT3;
0180 2D8A MOV R24,R10
0181 7088 ANDI R24,0x8
0182 2EA8 MOV R10,R24
(0093) LCD_OP_PORT=temp;
0183 BB88 OUT 0x18,R24
(0094) lcd_set_rw(); // Set LCD to READ
0184 9AC1 SBI 0x18,1
(0095) lcd_clear_rs();
0185 98C0 CBI 0x18,0
(0096) lcd_set_e();
0186 9AC2 SBI 0x18,2
(0097) delay_nus(3);
0187 E003 LDI R16,3
0188 E010 LDI R17,0
0189 DFB0 RCALL _delay_nus
(0098) high = LCD_IP_PORT; // read the high nibble.
018A B366 IN R22,0x16
(0099) lcd_clear_e(); // Disable LCD
018B 98C2 CBI 0x18,2
(0100) lcd_set_e();
018C 9AC2 SBI 0x18,2
(0101) asm("nop");
018D 0000 NOP
(0102) asm("nop");
018E 0000 NOP
(0103) low = LCD_IP_PORT; // read the low nibble.
018F B346 IN R20,0x16
(0104) lcd_clear_e(); // Disable LCD
0190 98C2 CBI 0x18,2
(0105) } while(high & 0x80);
0191 FD67 SBRC R22,7
0192 CFEC RJMP 0x017F
(0106) delay_nus(20);
0193 E104 LDI R16,0x14
0194 E010 LDI R17,0
0195 DFA4 RCALL _delay_nus
(0107) }
0196 D0CC RCALL pop_gset3
0197 9508 RET
_LCD_WriteControl:
temp --> R20
CMD --> R22
0198 D0E3 RCALL push_gset2
0199 2F60 MOV R22,R16
(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
019A DFE1 RCALL _LCD_Busy
019B 940E028D CALL 0x28D
(0115) LCD_DIR_PORT = 0xff; // LCD port output
(0116) temp=LCD_OP_PORT;
(0117) temp=temp&BIT3;
(0118) LCD_OP_PORT =(CMD & 0xf0)|temp; // Load high-data to port
(0119) lcd_clear_rw(); // Set LCD to write
(0120) lcd_clear_rs(); // Set LCD to command
019D 98C0 CBI 0x18,0
019E 940E0282 CALL <created procedures>
01A0 940E02A6 CALL 0x2A6
(0121) lcd_set_e(); // Write data to LCD
(0122) asm("nop");
(0123) asm("nop");
(0124) lcd_clear_e(); // Disable LCD
(0125) LCD_OP_PORT =(CMD<<4)|temp; // Load low-data to port
(0126) lcd_clear_rw(); // Set LCD to write
(0127) lcd_clear_rs(); // Set LCD to command
01A2 98C0 CBI 0x18,0
01A3 940E0282 CALL <created procedures>
(0128) lcd_set_e(); // Write data to LCD
(0129) asm("nop");
(0130) asm("nop");
(0131) lcd_clear_e(); // Disable LCD
(0132) }
01A5 D0BB RCALL pop_gset2
01A6 9508 RET
_LCD_WriteData:
temp --> R20
Data --> R22
01A7 D0D4 RCALL push_gset2
01A8 2F60 MOV R22,R16
(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
01A9 DFD2 RCALL _LCD_Busy
01AA 940E028D CALL 0x28D
(0140) LCD_DIR_PORT = 0xFF; // LCD port output
(0141) temp=LCD_OP_PORT;
(0142) temp=temp&BIT3;
(0143) LCD_OP_PORT =(Data & 0xf0)|temp; // Load high-data to port
(0144) lcd_clear_rw() ; // Set LCD to write
(0145) lcd_set_rs(); // Set LCD to data
01AC 9AC0 SBI 0x18,0
01AD 940E0282 CALL <created procedures>
01AF 940E02A6 CALL 0x2A6
(0146) lcd_set_e(); // Write data to LCD
(0147) asm("nop");
(0148) asm("nop");
(0149) lcd_clear_e(); // Disable LCD
(0150) LCD_OP_PORT = (Data << 4)|temp; // Load low-data to port
(0151) lcd_clear_rw() ; // Set LCD to write
(0152) lcd_set_rs(); // Set LCD to data
01B1 9AC0 SBI 0x18,0
01B2 940E0282 CALL <created procedures>
(0153) lcd_set_e(); // Write data to LCD
(0154) asm("nop");
(0155) asm("nop");
(0156) lcd_clear_e(); // Disable LCD
(0157) }
01B4 D0AC RCALL pop_gset2
01B5 9508 RET
(0158) // ********************************* //
(0159) // *** Initialize the LCD driver *** //
(0160) // ********************************* //
(0161) void Init_LCD(void)
(0162) {
(0163) LCD_INIT();
_Init_LCD:
01B6 DFA7 RCALL _LCD_INIT
(0164) LCD_WriteControl (LCD_FUNCTION_SET);
01B7 E208 LDI R16,0x28
01B8 DFDF RCALL _LCD_WriteControl
(0165) LCD_WriteControl (LCD_OFF);
01B9 E008 LDI R16,0x8
01BA DFDD RCALL _LCD_WriteControl
(0166) LCD_WriteControl (LCD_CLEAR);
01BB E001 LDI R16,1
01BC DFDB RCALL _LCD_WriteControl
(0167) LCD_WriteControl (LCD_MODE_SET);
01BD E006 LDI R16,6
01BE DFD9 RCALL _LCD_WriteControl
(0168) LCD_WriteControl (LCD_ON);
01BF E00C LDI R16,0xC
01C0 DFD7 RCALL _LCD_WriteControl
(0169) LCD_WriteControl (LCD_HOME);
01C1 E002 LDI R16,2
(0170) }
01C2 CFD5 RJMP _LCD_WriteControl
(0171) // ************************************************ //
(0172) // *** Clear the LCD screen (also homes cursor) *** //
(0173) // ************************************************ //
(0174) void LCD_Clear(void)
(0175) {
(0176) LCD_WriteControl(0x01);
_LCD_Clear:
01C3 E001 LDI R16,1
(0177) }
01C4 CFD3 RJMP _LCD_WriteControl
(0178) // *********************************************** //
(0179) // *** Position the LCD cursor at row 1, col 1 *** //
(0180) // *********************************************** //
(0181) void LCD_Home(void)
(0182) {
(0183) LCD_WriteControl(0x02);
_LCD_Home:
01C5 E002 LDI R16,2
(0184) }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -