📄 rctest.lst
字号:
__start:
__text_start:
0111 E5CF LDI R28,0x5F
0112 E0D4 LDI R29,4
0113 BFCD OUT 0x3D,R28
0114 BFDE OUT 0x3E,R29
0115 51C0 SUBI R28,0x10
0116 40D0 SBCI R29,0
0117 EA0A LDI R16,0xAA
0118 8308 STD Y+0,R16
0119 2400 CLR R0
011A E6E2 LDI R30,0x62
011B E0F0 LDI R31,0
011C E010 LDI R17,0
011D 36E2 CPI R30,0x62
011E 07F1 CPC R31,R17
011F F011 BEQ 0x0122
0120 9201 ST R0,Z+
0121 CFFB RJMP 0x011D
0122 8300 STD Z+0,R16
0123 E2E0 LDI R30,0x20
0124 E0F2 LDI R31,2
0125 E6A0 LDI R26,0x60
0126 E0B0 LDI R27,0
0127 E012 LDI R17,2
0128 32E2 CPI R30,0x22
0129 07F1 CPC R31,R17
012A F021 BEQ 0x012F
012B 95C8 LPM
012C 9631 ADIW R30,1
012D 920D ST R0,X+
012E CFF9 RJMP 0x0128
012F 940E02B6 CALL _main
_exit:
0131 CFFF RJMP _exit
FILE: E:\avr\RCtest\main.c
(0001) //ICC-AVR application builder : 2007-5-24 20:31:27
(0002) // Target : M16
(0003) // Crystal: 8.0000Mhz
(0004)
(0005) #include <iom16v.h>
(0006) #include <macros.h>
(0007) #include "font.h"
(0008)
(0009)
(0010) #define LCD_DC_PIN 0x04 // PB2
(0011) #define LCD_CE_PIN 0x02 // PB1
(0012) #define SPI_MOSI_PIN 0x20 // PB5
(0013) #define LCD_RST_PIN 0x01 // PB0
(0014) #define SPI_CLK_PIN 0x80 // PB7
(0015)
(0016) #define X_Length 45
(0017) #define X_Init 10
(0018) #define Y_Init 2
(0019)
(0020) /*--------------------------------------------------------------------------------------------------
(0021) Public function prototypes
(0022) --------------------------------------------------------------------------------------------------*/
(0023) void LcdInit ( void );
(0024) void LcdClear ( void );
(0025)
(0026) static void LcdSend ( unsigned char, unsigned char);
(0027) static void Delay ( void );
(0028) void LcdGotoXY ( unsigned char, unsigned char );
(0029)
(0030) unsigned int timer_count=0;
(0031)
(0032) void port_init(void)
(0033) {
(0034) PORTA = 0x00;
_port_init:
0132 2422 CLR R2
0133 BA2B OUT 0x1B,R2
(0035) DDRA = 0x00;
0134 BA2A OUT 0x1A,R2
(0036) PORTB = 0x00;
0135 BA28 OUT 0x18,R2
(0037) DDRB = 0x00;
0136 BA27 OUT 0x17,R2
(0038) PORTC = 0x00; //m103 output only
0137 BA25 OUT 0x15,R2
(0039) DDRC = 0x00;
0138 BA24 OUT 0x14,R2
(0040) PORTD = 0x00;
0139 BA22 OUT 0x12,R2
(0041) DDRD = 0x00;
013A BA21 OUT 0x11,R2
013B 9508 RET
(0042) }
(0043)
(0044) //TIMER0 initialize - prescale:1
(0045) // WGM: Normal
(0046) // desired value: 32uSec
(0047) // actual value: 32.000uSec (0.0%)
(0048) void timer0_init(void)
(0049) {
(0050) TCCR0 = 0x00; //stop
_timer0_init:
013C 2422 CLR R2
013D BE23 OUT 0x33,R2
(0051) TCNT0 = 0x00; //set count
013E BE22 OUT 0x32,R2
(0052) OCR0 = 0xFE; //set compare
013F EF8E LDI R24,0xFE
0140 BF8C OUT 0x3C,R24
(0053) TCCR0 = 0x01; //start timer
0141 E081 LDI R24,1
0142 BF83 OUT 0x33,R24
0143 9508 RET
_timer0_comp_isr:
0144 922A ST R2,-Y
0145 938A ST R24,-Y
0146 939A ST R25,-Y
0147 B62F IN R2,0x3F
0148 922A ST R2,-Y
(0054) }
(0055)
(0056) #pragma interrupt_handler timer0_comp_isr:20
(0057) void timer0_comp_isr(void)
(0058) {
(0059) //compare occured TCNT0=OCR0
(0060) TCNT0 = 0x00;
0149 2422 CLR R2
014A BE22 OUT 0x32,R2
(0061) timer_count++;
014B 91800060 LDS R24,timer_count
014D 91900061 LDS R25,timer_count+1
014F 9601 ADIW R24,1
0150 93900061 STS timer_count+1,R25
0152 93800060 STS timer_count,R24
0154 9029 LD R2,Y+
0155 BE2F OUT 0x3F,R2
0156 9199 LD R25,Y+
0157 9189 LD R24,Y+
0158 9029 LD R2,Y+
0159 9518 RETI
(0062) }
(0063) //call this routine to initialize all peripherals
(0064) void init_devices(void)
(0065) {
(0066) //stop errant interrupts until set up
(0067) CLI(); //disable all interrupts
_init_devices:
015A 94F8 BCLR 7
(0068) port_init();
015B DFD6 RCALL _port_init
(0069) MCUCR = 0x00;
015C 2422 CLR R2
015D BE25 OUT 0x35,R2
(0070) GICR = 0x00;
015E BE2B OUT 0x3B,R2
(0071) TIMSK = 0x02; //timer interrupt sources
015F E082 LDI R24,2
0160 BF89 OUT 0x39,R24
(0072) SEI(); //re-enable interrupts
0161 9478 BSET 7
0162 9508 RET
(0073) //all peripherals are now initialized
(0074) }
(0075)
(0076) void delay(void) //延时
(0077) {
(0078) unsigned int i=0;
_delay:
i --> R16
j --> R18
0163 2700 CLR R16
0164 2711 CLR R17
(0079) unsigned char j=0;
0165 2722 CLR R18
(0080) for(i=1;i!=0;i++)
0166 E001 LDI R16,1
0167 C007 RJMP 0x016F
(0081) {
(0082) for(j=1;j!=0;j++)
0168 E021 LDI R18,1
0169 C001 RJMP 0x016B
016A 9523 INC R18
016B 2322 TST R18
016C F7E9 BNE 0x016A
016D 5F0F SUBI R16,0xFF
016E 4F1F SBCI R17,0xFF
016F 3000 CPI R16,0
0170 0701 CPC R16,R17
0171 F7B1 BNE 0x0168
0172 9508 RET
_Delay100us:
i --> R20
x --> R16
0173 940E0441 CALL push_gset1
(0083) ;
(0084) }
(0085) }
(0086)
(0087) void Delay100us(unsigned char x)
(0088) {
(0089) unsigned char i; //4clock
(0090) for(i=147;x!=0;x--)
0175 E943 LDI R20,0x93
0176 C006 RJMP 0x017D
(0091) while(--i); //5 * i clock
0177 2F84 MOV R24,R20
0178 5081 SUBI R24,1
0179 2F48 MOV R20,R24
017A 2388 TST R24
017B F7D9 BNE 0x0177
017C 950A DEC R16
017D 2300 TST R16
017E F7C1 BNE 0x0177
017F 940E0444 CALL pop_gset1
0181 9508 RET
_Delay1ms:
n --> R20
0182 940E0441 CALL push_gset1
0184 01A8 MOVW R20,R16
(0092) }
(0093) void Delay1ms( unsigned int n)
(0094) {
(0095) for (;n!=0;n--){
0185 C004 RJMP 0x018A
(0096) Delay100us(10);
0186 E00A LDI R16,0xA
0187 DFEB RCALL _Delay100us
0188 5041 SUBI R20,1
0189 4050 SBCI R21,0
018A 3040 CPI R20,0
018B 0745 CPC R20,R21
018C F7C9 BNE 0x0186
018D 940E0444 CALL pop_gset1
018F 9508 RET
_Delay1s:
m --> R20
0190 940E0441 CALL push_gset1
0192 01A8 MOVW R20,R16
(0097) }
(0098) }
(0099) void Delay1s( unsigned int m) // m <= 6 ,when m==7, it is 1.
(0100) {
(0101) m=m*40;
0193 E208 LDI R16,0x28
0194 E010 LDI R17,0
0195 019A MOVW R18,R20
0196 940E0423 CALL empy16s
0198 01A8 MOVW R20,R16
(0102) for (;m!=0;m--){
0199 C004 RJMP 0x019E
(0103) Delay100us(250);
019A EF0A LDI R16,0xFA
019B DFD7 RCALL _Delay100us
019C 5041 SUBI R20,1
019D 4050 SBCI R21,0
019E 3040 CPI R20,0
019F 0745 CPC R20,R21
01A0 F7C9 BNE 0x019A
01A1 940E0444 CALL pop_gset1
01A3 9508 RET
(0104) }
(0105) }
(0106)
(0107)
(0108) /*--------------------------------------------------------------------------------------------------
(0109) Global Variables
(0110) 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,10个
(0111) --------------------------------------------------------------------------------------------------*/
(0112) //字模 "FUCK JAPAN"
(0113) unsigned char const X_TAB[] =
(0114) {0x7E,0x0A,0x0A,0x0A,0x00,0x7E,0x40,0x40,0x7E,0x00,0x7E,0x42,0x42,0x42,0x00,0x7E,0x18,0x24,0x42,0x00,0x00,0x00,0x42,0x7E,0x02,0x00,0x7C,0x12,0x12,0x7C,
(0115) 0x00,0x7E,0x0A,0x0A,0x0E,0x00,0x7C,0x12,0x12,0x7C,0x00,0x7E,0x08,0x10,0x7E};
(0116)
(0117)
(0118)
(0119)
(0120)
(0121)
(0122)
(0123) ////////////////////////////////////////////////////////////////////////////////////////////////////
(0124) ////////////////////////////////////////////////////////////////////////////////////////////////////
(0125) ////////////////////////////////////////////////////////////////////////////////////////////////////
(0126) ////////////////////////////////////////////////////////////////////////////////////////////////////
(0127)
(0128) /*--------------------------------------------------------------------------------------------------
(0129) Name : LcdInit
(0130) Description : Performs MCU SPI & LCD controller initialization.
(0131) Argument(s) : None.
(0132) Return value : None.
(0133) --------------------------------------------------------------------------------------------------*/
(0134) void LcdInit( void )
(0135) {
(0136) //unsigned char Clear;
(0137) // Pull-up on reset pin,上电复位端口,此时为高,不复位;
(0138) PORTB |= LCD_RST_PIN;
_LcdInit:
01A4 9AC0 SBI 0x18,0
(0139)
(0140) // Set output bits on port B,设置输出口;
(0141) DDRB |= LCD_RST_PIN | LCD_DC_PIN | LCD_CE_PIN | SPI_MOSI_PIN | SPI_CLK_PIN;
01A5 B387 IN R24,0x17
01A6 6A87 ORI R24,0xA7
01A7 BB87 OUT 0x17,R24
(0142)
(0143) Delay();
01A8 D04B RCALL _Delay
(0144)
(0145) // Toggle display reset pin.
(0146) PORTB &= ~LCD_RST_PIN; //上电复位;
01A9 98C0 CBI 0x18,0
(0147) Delay();
01AA D049 RCALL _Delay
(0148) PORTB |= LCD_RST_PIN; //复位完;
01AB 9AC0 SBI 0x18,0
(0149)
(0150) // SPI初始化;Enable SPI port: No interrupt, MSBit first, Master mode, CPOL->0, CPHA->0, Clk/4
(0151) SPCR = BIT(SPE)|BIT(MSTR); //使能SPI,主机模式;
01AC E580 LDI R24,0x50
01AD B98D OUT 0x0D,R24
(0152) //SPSR = 0x00; //似乎不用这几句也能正常运行;
(0153) //Clear= SPSR;
(0154) //Clear= SPDR;
(0155) // Disable LCD controller
(0156) PORTB |= LCD_CE_PIN;
01AE 9AC1 SBI 0x18,1
(0157)
(0158) LcdSend( 0x21, 0 ); // LCD Extended Commands.
01AF 2722 CLR R18
01B0 E201 LDI R16,0x21
01B1 D037 RCALL _LcdSend
(0159) LcdSend( 0xC8, 0 ); // Set LCD Vop (Contrast).
01B2 2722 CLR R18
01B3 EC08 LDI R16,0xC8
01B4 D034 RCALL _LcdSend
(0160) LcdSend( 0x06, 0 ); // Set Temp coefficent.
01B5 2722 CLR R18
01B6 E006 LDI R16,6
01B7 D031 RCALL _LcdSend
(0161) LcdSend( 0x13, 0 ); // LCD bias mode 1:48.
01B8 2722 CLR R18
01B9 E103 LDI R16,0x13
01BA D02E RCALL _LcdSend
(0162) LcdSend( 0x20, 0 ); // LCD Standard Commands, Horizontal addressing mode.
01BB 2722 CLR R18
01BC E200 LDI R16,0x20
01BD D02B RCALL _LcdSend
(0163) LcdSend( 0x0C, 0 ); // LCD in normal mode.
01BE 2722 CLR R18
01BF E00C LDI R16,0xC
01C0 D028 RCALL _LcdSend
(0164)
(0165) LcdClear();
01C1 D001 RCALL _LcdClear
01C2 9508 RET
_LcdClear:
i --> R20
01C3 940E0441 CALL push_gset1
(0166)
(0167) }
(0168)
(0169)
(0170) /*--------------------------------------------------------------------------------------------------
(0171) Name : LcdClear
(0172) Description : Clears the display.
(0173) Argument(s) : None.
(0174) Return value : None.
(0175) --------------------------------------------------------------------------------------------------*/
(0176) void LcdClear(void)
(0177) {
(0178) unsigned int i;
(0179)
(0180) LcdSend(0x0c, 0);
01C5 2722 CLR R18
01C6 E00C LDI R16,0xC
01C7 D021 RCALL _LcdSend
(0181) LcdSend(0x80, 0); //此时默认操作为清屏
01C8 2722 CLR R18
01C9 E800 LDI R16,0x80
01CA D01E RCALL _LcdSend
(0182)
(0183) for (i=0; i<504; i++)
01CB 2744 CLR R20
01CC 2755 CLR R21
01CD C005 RJMP 0x01D3
(0184) LcdSend(0, 1);
01CE E021 LDI R18,1
01CF 2700 CLR R16
01D0 D018 RCALL _LcdSend
01D1 5F4F SUBI R20,0xFF
01D2 4F5F SBCI R21,0xFF
01D3 3F48 CPI R20,0xF8
01D4 E0E1 LDI R30,1
01D5 075E CPC R21,R30
01D6 F3B8 BCS 0x01CE
01D7 940E0444 CALL pop_gset1
01D9 9508 RET
_LcdGotoXY:
Y --> R22
X --> R20
01DA 940E043F CALL push_gset2
01DC 2F62 MOV R22,R18
01DD 2F40 MOV R20,R16
(0185) }
(0186)
(0187)
(0188)
(0189) /*--------------------------------------------------------------------------------------------------
(0190) Name : LcdGotoXY 设置块坐标
(0191) Description : Sets cursor location to xy location corresponding to basic font size.
(0192) Argument(s) : x, y -> Coordinate for new cursor position. Range: 1,1 .. 14,6
(0193) Return value : None.
(0194) --------------------------------------------------------------------------------------------------*/
(0195) void LcdGotoXY(unsigned char X, unsigned char Y)
(0196) {
(0197) LcdSend(0x40 | Y, 0); // column
01DE 2722 CLR R18
01DF 2F06 MOV R16,R22
01E0 6400 ORI R16,0x40
01E1 D007 RCALL _LcdSend
(0198) LcdSend(0x80 | X, 0); // row
01E2 2722 CLR R18
01E3 2F04 MOV R16,R20
01E4 6800 ORI R16,0x80
01E5 D003 RCALL _LcdSend
01E6 940E0433 CALL pop_gset2
01E8 9508 RET
(0199) }
(0200)
(0201) /*--------------------------------------------------------------------------------------------------
(0202) Name : LcdSend
(0203) Description : Sends data to display controller.
(0204) Argument(s) : data -> Data to be sent
(0205) cd -> Command or data (see/use enum)
(0206) Return value : None.
(0207) --------------------------------------------------------------------------------------------------*/
(0208) static void LcdSend (unsigned char data, unsigned char command)
(0209) {
(0210) PORTB &= ~LCD_CE_PIN ; // 使能LCD
_LcdSend:
command --> R18
data --> R16
01E9 98C1 CBI 0x18,1
(0211) if (command == 0)
01EA 2322 TST R18
01EB F411 BNE 0x01EE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -