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

📄 main.s

📁 一个关于AVR单片机的例程
💻 S
📖 第 1 页 / 共 2 页
字号:
;   { 0x0C, 0x50, 0x50, 0x50, 0x3C },   // y
;   { 0x44, 0x64, 0x54, 0x4C, 0x44 }   // z
; };
; 
; 
; /*--------------------------------------------------------------------------------------------------
;                                  Public function prototypes
; --------------------------------------------------------------------------------------------------*/
; void LcdInit       ( void );
; void LcdClear      ( void );
; 
; static void LcdSend    ( unsigned char, unsigned char);
; static void Delay      ( void );
; void LcdGotoXY         ( unsigned char, unsigned char );
; 
; 
; /*--------------------------------------------------------------------------------------------------
;   Name         :  LcdInit
;   Description  :  Performs MCU SPI & LCD controller initialization.
;   Argument(s)  :  None.
;   Return value :  None.
; --------------------------------------------------------------------------------------------------*/
; void LcdInit( void )
; {    
	.dbline 136
;     //unsigned char Clear;
;     //  Pull-up on reset pin,上电复位端口,此时为高,不复位;
;     PORTB |= LCD_RST_PIN;
	sbi 0x18,0
	.dbline 139
; 
;     //  Set output bits on port B,设置输出口;
;     DDRB |= LCD_RST_PIN | LCD_DC_PIN | LCD_CE_PIN | SPI_MOSI_PIN | SPI_CLK_PIN;
	in R24,0x17
	ori R24,167
	out 0x17,R24
	.dbline 141
; 
;     Delay();
	xcall _Delay
	.dbline 144
; 
;     //  Toggle display reset pin.
;     PORTB &= ~LCD_RST_PIN; //上电复位;
	cbi 0x18,0
	.dbline 145
;     Delay();
	xcall _Delay
	.dbline 146
;     PORTB |= LCD_RST_PIN;  //复位完;
	sbi 0x18,0
	.dbline 149
; 
;     //  SPI初始化;Enable SPI port: No interrupt, MSBit first, Master mode, CPOL->0, CPHA->0, Clk/4
;     SPCR = BIT(SPE)|BIT(MSTR); //使能SPI,主机模式;
	ldi R24,80
	out 0xd,R24
	.dbline 154
;     //SPSR = 0x00;  //似乎不用这几句也能正常运行;
;     //Clear= SPSR;
;     //Clear= SPDR;
;     //  Disable LCD controller
;     PORTB |= LCD_CE_PIN;       
	sbi 0x18,1
	.dbline 156
; 
;     LcdSend( 0x21, 0 );  // LCD Extended Commands.
	clr R18
	ldi R16,33
	xcall _LcdSend
	.dbline 157
;     LcdSend( 0xC8, 0 );  // Set LCD Vop (Contrast).
	clr R18
	ldi R16,200
	xcall _LcdSend
	.dbline 158
;     LcdSend( 0x06, 0 );  // Set Temp coefficent.
	clr R18
	ldi R16,6
	xcall _LcdSend
	.dbline 159
;     LcdSend( 0x13, 0 );  // LCD bias mode 1:48.
	clr R18
	ldi R16,19
	xcall _LcdSend
	.dbline 160
;     LcdSend( 0x20, 0 );  // LCD Standard Commands, Horizontal addressing mode.
	clr R18
	ldi R16,32
	xcall _LcdSend
	.dbline 161
;     LcdSend( 0x0C, 0 );  // LCD in normal mode.
	clr R18
	ldi R16,12
	xcall _LcdSend
	.dbline 163
; 
;     LcdClear();
	xcall _LcdClear
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LcdClear _LcdClear fV
;              i -> R20,R21
	.even
_LcdClear::
	xcall push_gset1
	.dbline -1
	.dbline 174
;    
; }
; 
; /*--------------------------------------------------------------------------------------------------
;   Name         :  LcdClear
;   Description  :  Clears the display.
;   Argument(s)  :  None.
;   Return value :  None.
; --------------------------------------------------------------------------------------------------*/
; void LcdClear(void)
; {
	.dbline 177
; unsigned int i;
; 
; LcdSend(0x0c, 0); 
	clr R18
	ldi R16,12
	xcall _LcdSend
	.dbline 178
; LcdSend(0x80, 0); //此时默认操作为清屏
	clr R18
	ldi R16,128
	xcall _LcdSend
	.dbline 180
; 
; for (i=0; i<504; i++)
	clr R20
	clr R21
	xjmp L6
L3:
	.dbline 181
	ldi R18,1
	clr R16
	xcall _LcdSend
L4:
	.dbline 180
	subi R20,255  ; offset = 1
	sbci R21,255
L6:
	.dbline 180
	cpi R20,248
	ldi R30,1
	cpc R21,R30
	brlo L3
	.dbline -2
L2:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbend
	.dbfunc e LcdGotoXY _LcdGotoXY fV
;              Y -> R22
;              X -> R20
	.even
_LcdGotoXY::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 191
; LcdSend(0, 1); 
; }
; 
; /*--------------------------------------------------------------------------------------------------
;   Name         :  LcdGotoXY 设置块坐标
;   Description  :  Sets cursor location to xy location corresponding to basic font size.
;   Argument(s)  :  x, y -> Coordinate for new cursor position. Range: 1,1 .. 14,6
;   Return value :  None.
; --------------------------------------------------------------------------------------------------*/
; void LcdGotoXY(unsigned char X, unsigned char Y)
; {
	.dbline 192
; LcdSend(0x40 | Y, 0); // column
	clr R18
	mov R16,R22
	ori R16,64
	xcall _LcdSend
	.dbline 193
; LcdSend(0x80 | X, 0); // row
	clr R18
	mov R16,R20
	ori R16,128
	xcall _LcdSend
	.dbline -2
L7:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r Y 22 c
	.dbsym r X 20 c
	.dbend
	.dbfunc s LcdSend _LcdSend fV
;        command -> R18
;           data -> R16
	.even
_LcdSend:
	.dbline -1
	.dbline 204
; }
; 
; /*--------------------------------------------------------------------------------------------------
;   Name         :  LcdSend
;   Description  :  Sends data to display controller.
;   Argument(s)  :  data -> Data to be sent
;                   cd   -> Command or data (see/use enum)
;   Return value :  None.
; --------------------------------------------------------------------------------------------------*/
; static void LcdSend (unsigned char data, unsigned char command)
; {
	.dbline 205
; PORTB &= ~LCD_CE_PIN ; // 使能LCD
	cbi 0x18,1
	.dbline 206
; if (command == 0)
	tst R18
	brne L9
	.dbline 207
; PORTB &= ~LCD_DC_PIN ; // 传送命令
	cbi 0x18,2
	xjmp L10
L9:
	.dbline 209
; else
; PORTB |= LCD_DC_PIN ; // 传送数据
	sbi 0x18,2
L10:
	.dbline 211
; 
; SPDR = data; // 传送数据到SPI寄存器
	out 0xf,R16
L11:
	.dbline 213
L12:
	.dbline 213
; 
; while ((SPSR & 0x80) == 0); // 等待数据传送完毕
	sbis 0xe,7
	rjmp L11
	.dbline 215
; 
; PORTB |= LCD_CE_PIN ; // 关闭LCD
	sbi 0x18,1
	.dbline -2
L8:
	.dbline 0 ; func end
	ret
	.dbsym r command 18 c
	.dbsym r data 16 c
	.dbend
	.dbfunc s Delay _Delay fV
;              i -> R16,R17
	.even
_Delay:
	.dbline -1
	.dbline 225
; }
; 
; /*--------------------------------------------------------------------------------------------------
;   Name         :  Delay
;   Description  :  Uncalibrated delay for LCD init routine.
;   Argument(s)  :  None.
;   Return value :  None.
; --------------------------------------------------------------------------------------------------*/
; static void Delay ( void )
; {
	.dbline 227
	ldi R16,-12000
	ldi R17,-47
L15:
	.dbline 227
L16:
	.dbline 227
;     int i;
;     for ( i = -12000; i < 12000; i++ );
	subi R16,255  ; offset = 1
	sbci R17,255
	.dbline 227
	cpi R16,224
	ldi R30,46
	cpc R17,R30
	brlt L15
	.dbline -2
L14:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 I
	.dbend
	.dbfunc e main _main fV
;              i -> R20
;              X -> R22
	.even
_main::
	.dbline -1
	.dbline 238
; }
; 
; /*--------------------------------------------------------------------------------------------------
;   Name         :  main
;   Description  :  
;   Argument(s)  :  
;   Return value :  None.
; --------------------------------------------------------------------------------------------------*/
; 
; void main(void)
; {
	.dbline 239
;   unsigned char X=0,i=0;  //v=0,按行显示,x对应某个bank(0~83)
	clr R22
	.dbline 239
	clr R20
	.dbline 240
;   LcdInit();
	xcall _LcdInit
	xjmp L21
L20:
	.dbline 243
;   
;   while(1)
;   {
	.dbline 244
;     LcdGotoXY(X_Init,Y_Init);
	clr R18
	clr R16
	xcall _LcdGotoXY
	.dbline 246
;    // for(X=0;X<X_Length;X++)LcdSend(X_TAB[X],1);
;    for(i=0;i<100;i++)
	clr R20
	xjmp L26
L23:
	.dbline 247
;    {
	.dbline 248
;     for(X=0;X<5;X++)
	clr R22
	xjmp L30
L27:
	.dbline 249
	.dbline 250
	ldi R18,1
	ldi R24,5
	mul R24,R20
	movw R2,R0
	ldi R24,<_FontLookup
	ldi R25,>_FontLookup
	add R2,R24
	adc R3,R25
	mov R30,R22
	clr R31
	add R30,R2
	adc R31,R3
	lpm R16,Z
	xcall _LcdSend
	.dbline 251
L28:
	.dbline 248
	inc R22
L30:
	.dbline 248
	cpi R22,5
	brlo L27
	.dbline 252
L24:
	.dbline 246
	inc R20
L26:
	.dbline 246
	cpi R20,100
	brlo L23
	.dbline 253
L21:
	.dbline 242
	xjmp L20
X0:
	.dbline -2
L19:
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r X 22 c
	.dbend

⌨️ 快捷键说明

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