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

📄 lcd.lst

📁 l602驱动程序 数据总线为4根 增加了io利用率
💻 LST
📖 第 1 页 / 共 3 页
字号:
   1               		.file	"lcd.c"
   2               		.arch atmega16
   3               	__SREG__ = 0x3f
   4               	__SP_H__ = 0x3e
   5               	__SP_L__ = 0x3d
   6               	__tmp_reg__ = 0
   7               	__zero_reg__ = 1
   8               		.global __do_copy_data
   9               		.global __do_clear_bss
  11               		.text
  12               	.Ltext0:
  68               	.global	LCDBusyLoop
  70               	LCDBusyLoop:
   1:lcd.c         **** #include <avr/io.h>
   2:lcd.c         **** #include <inttypes.h>
   3:lcd.c         **** 
   4:lcd.c         **** #ifndef F_CPU
   5:lcd.c         **** 	#define F_CPU 12000000UL
   6:lcd.c         **** #endif
   7:lcd.c         **** 
   8:lcd.c         **** #include <util/delay.h>
   9:lcd.c         **** 
  10:lcd.c         **** #include "lcd.h"
  11:lcd.c         **** 
  12:lcd.c         **** 
  13:lcd.c         **** 
  14:lcd.c         **** #define LCD_DATA_PORT 	PORT(LCD_DATA)
  15:lcd.c         **** #define LCD_E_PORT 		PORT(LCD_E)
  16:lcd.c         **** #define LCD_RS_PORT 	PORT(LCD_RS)
  17:lcd.c         **** #define LCD_RW_PORT 	PORT(LCD_RW)
  18:lcd.c         **** 
  19:lcd.c         **** #define LCD_DATA_DDR 	DDR(LCD_DATA)
  20:lcd.c         **** #define LCD_E_DDR 		DDR(LCD_E)
  21:lcd.c         **** #define LCD_RS_DDR 		DDR(LCD_RS)
  22:lcd.c         **** #define LCD_RW_DDR 		DDR(LCD_RW)
  23:lcd.c         **** 
  24:lcd.c         **** #define LCD_DATA_PIN	PIN(LCD_DATA)
  25:lcd.c         **** 
  26:lcd.c         **** #define SET_E() (LCD_E_PORT|=(1<<LCD_E_POS))
  27:lcd.c         **** #define SET_RS() (LCD_RS_PORT|=(1<<LCD_RS_POS))
  28:lcd.c         **** #define SET_RW() (LCD_RW_PORT|=(1<<LCD_RW_POS))
  29:lcd.c         **** 
  30:lcd.c         **** #define CLEAR_E() (LCD_E_PORT&=(~(1<<LCD_E_POS)))
  31:lcd.c         **** #define CLEAR_RS() (LCD_RS_PORT&=(~(1<<LCD_RS_POS)))
  32:lcd.c         **** #define CLEAR_RW() (LCD_RW_PORT&=(~(1<<LCD_RW_POS)))
  33:lcd.c         **** 
  34:lcd.c         **** 
  35:lcd.c         **** 
  36:lcd.c         **** void LCDByte(uint8_t c,uint8_t isdata)
  37:lcd.c         **** {
  38:lcd.c         **** //Sends a byte to the LCD in 4bit mode
  39:lcd.c         **** //cmd=0 for data
  40:lcd.c         **** //cmd=1 for command
  41:lcd.c         **** 
  42:lcd.c         **** 
  43:lcd.c         **** //NOTE: THIS FUNCTION RETURS ONLY WHEN LCD HAS PROCESSED THE COMMAND
  44:lcd.c         **** 
  45:lcd.c         **** uint8_t hn,ln;			//Nibbles
  46:lcd.c         **** uint8_t temp;
  47:lcd.c         **** 
  48:lcd.c         **** hn=c>>4;
  49:lcd.c         **** ln=(c & 0x0F);
  50:lcd.c         **** 
  51:lcd.c         **** if(isdata==0)
  52:lcd.c         **** 	CLEAR_RS();
  53:lcd.c         **** else
  54:lcd.c         **** 	SET_RS();
  55:lcd.c         **** 
  56:lcd.c         **** _delay_us(0.500);		//tAS
  57:lcd.c         **** 
  58:lcd.c         **** SET_E();
  59:lcd.c         **** 
  60:lcd.c         **** //Send high nibble
  61:lcd.c         **** 
  62:lcd.c         **** temp=(LCD_DATA_PORT & 0XF0)|(hn);
  63:lcd.c         **** LCD_DATA_PORT=temp;
  64:lcd.c         **** 
  65:lcd.c         **** _delay_us(1);			//tEH
  66:lcd.c         **** 
  67:lcd.c         **** //Now data lines are stable pull E low for transmission
  68:lcd.c         **** 
  69:lcd.c         **** CLEAR_E();
  70:lcd.c         **** 
  71:lcd.c         **** _delay_us(1);
  72:lcd.c         **** 
  73:lcd.c         **** //Send the lower nibble
  74:lcd.c         **** SET_E();
  75:lcd.c         **** 
  76:lcd.c         **** temp=(LCD_DATA_PORT & 0XF0)|(ln);
  77:lcd.c         **** 
  78:lcd.c         **** LCD_DATA_PORT=temp;
  79:lcd.c         **** 
  80:lcd.c         **** _delay_us(1);			//tEH
  81:lcd.c         **** 
  82:lcd.c         **** //SEND
  83:lcd.c         **** 
  84:lcd.c         **** CLEAR_E();
  85:lcd.c         **** 
  86:lcd.c         **** _delay_us(1);			//tEL
  87:lcd.c         **** 
  88:lcd.c         **** LCDBusyLoop();
  89:lcd.c         **** }
  90:lcd.c         **** 
  91:lcd.c         **** void LCDBusyLoop()
  92:lcd.c         **** {
  71               	 prologue end (size=0) */
  73               	.LM1:
  74               		in r24,52-0x20
  93:lcd.c         **** 	//This function waits till lcd is BUSY
  94:lcd.c         **** 
  95:lcd.c         **** 	uint8_t busy,status=0x00,temp;
  96:lcd.c         **** 
  97:lcd.c         **** 	//Change Port to input type because we are reading data
  98:lcd.c         **** 	LCD_DATA_DDR&=0xF0;
  75               	i r24,lo8(-16)
  76               		out 52-0x20,r24
  78 0002 807F      	.LM2:
  79 0004 84BB      		sbi 50-0x20,5
  99:lcd.c         **** 
 100:lcd.c         **** 	//change LCD mode
 101:lcd.c         **** 	SET_RW();		//Read mode
  80               	bn	68,0,102,.LM3-LCDBusyLoop
  81               	.LM3:
  82 0006 959A      		cbi 50-0x20,6
 102:lcd.c         **** 	CLEAR_RS();		//Read status
  83               	B54:
  84               	.LBB55:
  85 0008 9698      	.LBB56:
  86               	.LBB57:
  88               	.Ltext1:
  90               	.LM4:
  91               		ldi r24,lo8(1)
   1:c:/winavr/bin/../avr/include/util/delay.h **** /* Copyright (c) 2002, Marek Michalkiewicz
   2:c:/winavr/bin/../avr/include/util/delay.h ****    Copyright (c) 2004,2005 Joerg Wunsch
   3:c:/winavr/bin/../avr/include/util/delay.h ****    All rights reserved.
   4:c:/winavr/bin/../avr/include/util/delay.h **** 
   5:c:/winavr/bin/../avr/include/util/delay.h ****    Redistribution and use in source and binary forms, with or without
   6:c:/winavr/bin/../avr/include/util/delay.h ****    modification, are permitted provided that the following conditions are met:
   7:c:/winavr/bin/../avr/include/util/delay.h **** 
   8:c:/winavr/bin/../avr/include/util/delay.h ****    * Redistributions of source code must retain the above copyright
   9:c:/winavr/bin/../avr/include/util/delay.h ****      notice, this list of conditions and the following disclaimer.
  10:c:/winavr/bin/../avr/include/util/delay.h **** 
  11:c:/winavr/bin/../avr/include/util/delay.h ****    * Redistributions in binary form must reproduce the above copyright
  12:c:/winavr/bin/../avr/include/util/delay.h ****      notice, this list of conditions and the following disclaimer in
  13:c:/winavr/bin/../avr/include/util/delay.h ****      the documentation and/or other materials provided with the
  14:c:/winavr/bin/../avr/include/util/delay.h ****      distribution.
  15:c:/winavr/bin/../avr/include/util/delay.h **** 
  16:c:/winavr/bin/../avr/include/util/delay.h ****    * Neither the name of the copyright holders nor the names of
  17:c:/winavr/bin/../avr/include/util/delay.h ****      contributors may be used to endorse or promote products derived
  18:c:/winavr/bin/../avr/include/util/delay.h ****      from this software without specific prior written permission.
  19:c:/winavr/bin/../avr/include/util/delay.h **** 
  20:c:/winavr/bin/../avr/include/util/delay.h ****   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21:c:/winavr/bin/../avr/include/util/delay.h ****   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22:c:/winavr/bin/../avr/include/util/delay.h ****   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23:c:/winavr/bin/../avr/include/util/delay.h ****   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  24:c:/winavr/bin/../avr/include/util/delay.h ****   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25:c:/winavr/bin/../avr/include/util/delay.h ****   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26:c:/winavr/bin/../avr/include/util/delay.h ****   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27:c:/winavr/bin/../avr/include/util/delay.h ****   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28:c:/winavr/bin/../avr/include/util/delay.h ****   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29:c:/winavr/bin/../avr/include/util/delay.h ****   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30:c:/winavr/bin/../avr/include/util/delay.h ****   POSSIBILITY OF SUCH DAMAGE. */
  31:c:/winavr/bin/../avr/include/util/delay.h **** 
  32:c:/winavr/bin/../avr/include/util/delay.h **** /* $Id: delay.h,v 1.1.2.1 2005/12/12 23:19:49 joerg_wunsch Exp $ */
  33:c:/winavr/bin/../avr/include/util/delay.h **** 
  34:c:/winavr/bin/../avr/include/util/delay.h **** #ifndef _UTIL_DELAY_H_
  35:c:/winavr/bin/../avr/include/util/delay.h **** #define _UTIL_DELAY_H_ 1
  36:c:/winavr/bin/../avr/include/util/delay.h **** 
  37:c:/winavr/bin/../avr/include/util/delay.h **** #include <inttypes.h>
  38:c:/winavr/bin/../avr/include/util/delay.h **** 
  39:c:/winavr/bin/../avr/include/util/delay.h **** /** \defgroup util_delay <util/delay.h>: Busy-wait delay loops
  40:c:/winavr/bin/../avr/include/util/delay.h ****     \code
  41:c:/winavr/bin/../avr/include/util/delay.h ****     #define F_CPU 1000000UL  // 1 MHz
  42:c:/winavr/bin/../avr/include/util/delay.h ****     //#define F_CPU 14.7456E6
  43:c:/winavr/bin/../avr/include/util/delay.h ****     #include <util/delay.h>
  44:c:/winavr/bin/../avr/include/util/delay.h ****     \endcode
  45:c:/winavr/bin/../avr/include/util/delay.h **** 
  46:c:/winavr/bin/../avr/include/util/delay.h ****     \note As an alternative method, it is possible to pass the
  47:c:/winavr/bin/../avr/include/util/delay.h ****     F_CPU macro down to the compiler from the Makefile.
  48:c:/winavr/bin/../avr/include/util/delay.h ****     Obviously, in that case, no \c \#define statement should be
  49:c:/winavr/bin/../avr/include/util/delay.h ****     used.
  50:c:/winavr/bin/../avr/include/util/delay.h **** 
  51:c:/winavr/bin/../avr/include/util/delay.h ****     The functions in this header file implement simple delay loops
  52:c:/winavr/bin/../avr/include/util/delay.h ****     that perform a busy-waiting.  They are typically used to
  53:c:/winavr/bin/../avr/include/util/delay.h ****     facilitate short delays in the program execution.  They are
  54:c:/winavr/bin/../avr/include/util/delay.h ****     implemented as count-down loops with a well-known CPU cycle
  55:c:/winavr/bin/../avr/include/util/delay.h ****     count per loop iteration.  As such, no other processing can
  56:c:/winavr/bin/../avr/include/util/delay.h ****     occur simultaneously.  It should be kept in mind that the
  57:c:/winavr/bin/../avr/include/util/delay.h ****     functions described here do not disable interrupts.
  58:c:/winavr/bin/../avr/include/util/delay.h **** 
  59:c:/winavr/bin/../avr/include/util/delay.h ****     In general, for long delays, the use of hardware timers is
  60:c:/winavr/bin/../avr/include/util/delay.h ****     much preferrable, as they free the CPU, and allow for
  61:c:/winavr/bin/../avr/include/util/delay.h ****     concurrent processing of other events while the timer is
  62:c:/winavr/bin/../avr/include/util/delay.h ****     running.  However, in particular for very short delays, the
  63:c:/winavr/bin/../avr/include/util/delay.h ****     overhead of setting up a hardware timer is too much compared
  64:c:/winavr/bin/../avr/include/util/delay.h ****     to the overall delay time.
  65:c:/winavr/bin/../avr/include/util/delay.h **** 
  66:c:/winavr/bin/../avr/include/util/delay.h ****     Two inline functions are provided for the actual delay algorithms.
  67:c:/winavr/bin/../avr/include/util/delay.h **** 
  68:c:/winavr/bin/../avr/include/util/delay.h ****     Two wrapper functions allow the specification of microsecond, and
  69:c:/winavr/bin/../avr/include/util/delay.h ****     millisecond delays directly, using the application-supplied macro
  70:c:/winavr/bin/../avr/include/util/delay.h ****     F_CPU as the CPU clock frequency (in Hertz).  These functions
  71:c:/winavr/bin/../avr/include/util/delay.h ****     operate on double typed arguments, however when optimization is
  72:c:/winavr/bin/../avr/include/util/delay.h ****     turned on, the entire floating-point calculation will be done at
  73:c:/winavr/bin/../avr/include/util/delay.h ****     compile-time.
  74:c:/winavr/bin/../avr/include/util/delay.h **** 
  75:c:/winavr/bin/../avr/include/util/delay.h ****     \note When using _delay_us() and _delay_ms(), the expressions
  76:c:/winavr/bin/../avr/include/util/delay.h ****     passed as arguments to these functions shall be compile-time
  77:c:/winavr/bin/../avr/include/util/delay.h ****     constants, otherwise the floating-point calculations to setup the
  78:c:/winavr/bin/../avr/include/util/delay.h ****     loops will be done at run-time, thereby drastically increasing
  79:c:/winavr/bin/../avr/include/util/delay.h ****     both the resulting code size, as well as the time required to
  80:c:/winavr/bin/../avr/include/util/delay.h ****     setup the loops.
  81:c:/winavr/bin/../avr/include/util/delay.h **** */
  82:c:/winavr/bin/../avr/include/util/delay.h **** 
  83:c:/winavr/bin/../avr/include/util/delay.h **** #if !defined(__DOXYGEN__)
  84:c:/winavr/bin/../avr/include/util/delay.h **** static inline void _delay_loop_1(uint8_t __count) __attribute__((always_inline));
  85:c:/winavr/bin/../avr/include/util/delay.h **** static inline void _delay_loop_2(uint16_t __count) __attribute__((always_inline));
  86:c:/winavr/bin/../avr/include/util/delay.h **** static inline void _delay_us(double __us) __attribute__((always_inline));
  87:c:/winavr/bin/../avr/include/util/delay.h **** static inline void _delay_ms(double __ms) __attribute__((always_inline));
  88:c:/winavr/bin/../avr/include/util/delay.h **** #endif
  89:c:/winavr/bin/../avr/include/util/delay.h **** 
  90:c:/winavr/bin/../avr/include/util/delay.h **** /** \ingroup util_delay
  91:c:/winavr/bin/../avr/include/util/delay.h **** 
  92:c:/winavr/bin/../avr/include/util/delay.h ****     Delay loop using an 8-bit counter \c __count, so up to 256
  93:c:/winavr/bin/../avr/include/util/delay.h ****     iterations are possible.  (The value 256 would have to be passed
  94:c:/winavr/bin/../avr/include/util/delay.h ****     as 0.)  The loop executes three CPU cycles per iteration, not
  95:c:/winavr/bin/../avr/include/util/delay.h ****     including the overhead the compiler needs to setup the counter
  96:c:/winavr/bin/../avr/include/util/delay.h ****     register.
  97:c:/winavr/bin/../avr/include/util/delay.h **** 
  98:c:/winavr/bin/../avr/include/util/delay.h ****     Thus, at a CPU speed of 1 MHz, delays of up to 768 microseconds
  99:c:/winavr/bin/../avr/include/util/delay.h ****     can be achieved.
 100:c:/winavr/bin/../avr/include/util/delay.h **** */
 101:c:/winavr/bin/../avr/include/util/delay.h **** void
 102:c:/winavr/bin/../avr/include/util/delay.h **** _delay_loop_1(uint8_t __count)
 103:c:/winavr/bin/../avr/include/util/delay.h **** {
 104:c:/winavr/bin/../avr/include/util/delay.h **** 	__asm__ volatile (
  92               	/
  93               		1: dec r24
  94 000a 81E0      		brne 1b
  95               	/* #NOAPP */
  96 000c 8A95      		ldi r18,lo8(1)
  97 000e 01F4      		ldi r19,lo8(2)
  98               	.L2:
  99 0010 21E0      	.LBE57:
 100 0012 32E0      	.LBE56:
 101               	.LBE55:
 102               	.LBE54:
 104               	.Ltext2:
 106               	.LM5:
 107               		sbi 50-0x20,7
 103:lcd.c         **** 
 104:lcd.c         **** 	//Let the RW/RS lines stabilize
 105:lcd.c         **** 
 106:lcd.c         **** 	_delay_us(0.5);		//tAS
 107:lcd.c         **** 
 108:lcd.c         **** 	
 109:lcd.c         **** 	do
 110:lcd.c         **** 	{
 111:lcd.c         **** 
 112:lcd.c         **** 		SET_E();
 108               	.LBB60:
 109               	.LBB61:
 111               	.Ltext3:
 113               	.LM6:
 114               		mov r24,r18
 115               	/* #APP */
 116               		1: dec r24
 117               		brne 1b
 118               	/* #NOAPP */
 119 0016 822F      	.LBE61:
 120               	.LBE60:
 121 0018 8A95      	.LBE59:
 122 001a 01F4      	.LBE58:
 124               	.Ltext4:
 126               	.LM7:
 127               		in r24,51-0x20
 129               	.LM8:
 113:lcd.c         **** 
 114:lcd.c         **** 		//Wait tDA for data to become available
 115:lcd.c         **** 		_delay_us(0.5);
 116:lcd.c         **** 
 117:lcd.c         **** 		status=LCD_DATA_PIN;
 130               	f0
 131               	.LBB62:
 132 001c 83B3      	.LBB63:
 118:lcd.c         **** 		status=status<<4;
 133               	B64:
 134               	.LBB65:
 136 0020 807F      	.Ltext5:
 138               	.LM9:
 139               		mov r25,r18
 140               	/* #APP */
 141               		1: dec r25
 142               		brne 1b
 143               	/* #NOAPP */
 144               	.LBE65:
 145 0022 922F      	.LBE64:
 146               	.LBE63:
 147 0024 9A95      	.LBE62:
 149               	.Ltext6:
 151               	.LM10:
 152               		cbi 50-0x20,7
 153               	.LBB66:
 154               	.LBB67:
 155               	.LBB68:
 119:lcd.c         **** 
 120:lcd.c         **** 		_delay_us(0.5);
 121:lcd.c         **** 
 122:lcd.c         **** 		//Pull E low
 123:lcd.c         **** 		CLEAR_E();
 156               	avr/bin/../avr/include/util/delay.h",132,0,0,.Ltext7
 157               	.Ltext7:
 159               	.LM11:
 160               		mov r25,r19
 161               	/* #APP */
 162               		1: dec r25
 163               		brne 1b
 164               	/* #NOAPP */
 165               	.LBE69:
 166               	.LBE68:
 167 002a 932F      	.LBE67:
 168               	.LBE66:
 170 002e 01F4      	.Ltext8:
 172               	.LM12:
 173               		sbi 50-0x20,7
 174               	.LBB70:
 175               	.LBB71:
 176               	.LBB72:
 177               	.LBB73:

⌨️ 快捷键说明

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