历史上的今天
返回首页

历史上的今天

今天是:2025年03月12日(星期三)

正在发生

2018年03月12日 | PIC16Fxxx的LCD驱动程序(适用于HD44780兼容的驱动器)

2018-03-12 来源:eefocus

PIC16Fxxx的LCD驱动程序(适用于HD44780兼容的驱动器)

;************************************************
;* LCD.ASM                                      *
;************************************************
;* Contains subroutines to control an external  *
;* lcd panel in 4-bit mode.  These routines    *
;* were designed specifically for the panel on  *
;* the MCU201 workshop demo board, but should  *
;* work with other LCDs with a HD44780 type    *
;* controller.                                  *
;* Routines include:                            *
;*  - InitLCD to initialize the LCD panel      *
;*  - putcLCD to write a character to LCD      *
;*  - SendCmd to write a command to LCD        *
;*  - clrLCD to clear the LCD display          *
;*  - L1homeLCD to return cursor to line 1 home*
;*  - L2homeLCD to return cursor to line 2 home*
;*  - PutHexLCD to write a HEX Code to LCD    *
;*  - Hex2ASCII to convert 4 bits to ASCII Code*
;************************************************
;
  list p=16f877
  #i nclude  
;
; Defines for I/O ports that provide LCD data & control
; PORTB.0 - PORTB.3 are Data PINs for LCD Module
; PORTB.4 is E Control Signal for LCD
; PORTB.5 is RS Control Signal for LCD
; PORTC.2 is BackLight Control pin for LCD Module 
;
  global InitLCD
  global putcLCD
  global clrLCD
  global L1homeLCD
  global L2homeLCD
  global  SendCmd
  global PutHexLCD
  global Hex2ASCII
;
LCD_DATA equ PORTB
LCD_CNTL equ PORTB

; Defines for I/O pins that provide LCD control
RS  equ 5
E  equ 4

; LCD Module commands
DISP_ON  EQU 0x00C ; Display on
DISP_ON_C EQU 0x00E ; Display on, Cursor on
DISP_ON_B EQU 0x00F ; Display on, Cursor on, Blink cursor
DISP_OFF EQU 0x008 ; Display off
CLR_DISP EQU 0x001 ; Clear the Display
ENTRY_INC EQU 0x006 ;
ENTRY_INC_S EQU 0x007 ;
ENTRY_DEC EQU 0x004 ;
ENTRY_DEC_S EQU 0x005 ;
DD_RAM_ADDR EQU 0x080 ; Least SignifiCANt 7-bit are for address
DD_RAM_UL EQU 0x080 ; Upper Left coner of the Display
;

; Directs linker to provide 4 variables in GPR memory
  UDATA
Byte  RES 1
Byte1  RES 1
Count  RES 1
Count1  RES 1
W_BUFR  RES 1
Hex_Bfr  RES 1
;
PROG1  CODE  
;*******************************************************************
;* The LCD Module Subroutines                                      *
;* Command sequence for 2 lines of 5x16 characters                *
;*******************************************************************
InitLCD
  BANKSEL TRISB
  movlw 0xc0  ; Initialize inputs/outputs for LCD
  movwf TRISB
  BANKSEL LCD_DATA
  clrf LCD_DATA ; Clear LCD data & control bits
;
  movlw .50  ; Power=On delay 50mS

  Call  Delay_MS
;
  movlw   0x02  ; Init for 4-bit interface
  call Send_4bit
  movlw .10  ;  Delay 10 mS
  Call  Delay_MS
;
  movlw b'00000011' ; Fully Initial LCD module 
  call Send_4bit ; Sent '0011' data 4 time
  movlw .5  ; Delay 5mS
  Call  Delay_MS
  movlw b'00000011'
  call Send_4bit
  call Delay_1MS ; Delay 1mS
   movlw b'00000011'
   call Send_4bit
   movlw b'00000010'
   call Send_4bit 
;
  movlw b'00101000' ; Set 2 lines & 5 x 7 dots
  call SendCmd
  movlw DISP_ON  ; Turn display on (0x0C)
  call SendCmd
  movlw ENTRY_INC ; Configure cursor movement
  call SendCmd
  movlw DD_RAM_ADDR ; Set writes for display memory
  call SendCmd
  return
;
;*******************************************************************
;*SendChar - Sends character to LCD                                *
;*This routine splits the character into the upper and lower       * 
;*nibbles and sends them to the LCD, upper nibble first.           *
;*******************************************************************
putcLCD
  banksel Byte
  movwf Byte  ; Save WREG in Byte variable
  call Delay_1MS
  swapf Byte,W  ; Write upper nibble first
  andlw 0x0f
  movwf LCD_DATA
  bsf LCD_CNTL, RS ; Set for data
  bsf LCD_CNTL, E ; CLOCk nibble into LCD
  bcf LCD_CNTL, E
  movf Byte,W  ; Write lower nibble last
  andlw 0x0f
  movwf LCD_DATA
  bsf LCD_CNTL, RS ; Set for data
  bsf LCD_CNTL, E ; Clock nibble into LCD
  bcf LCD_CNTL, E
  return
;
;*********************************************************************
;*      To put the HEX value to LCD Display ,,
;*      High nibble first than Low nibble 
;*      Input : W Reg.
;*********************************************************************
PutHexLCD
  banksel W_BUFR
  movwf W_BUFR  ; Save W Register !!
  swapf W_BUFR,W  ; High nibble first !! 
  call Hex2ASCII
  call putcLCD
;
  movf W_BUFR,W
  call Hex2ASCII
  call putcLCD
  return
;
;******************************************************************
;*       Convert a low nibble to ASCII code
;*       Input : W Reg.
;*       Output: W Reg.
;******************************************************************
Hex2ASCII
  andlw 0x0f  ; Mask Bit 4 to 7
  movwf Hex_Bfr
  sublw .09
  btfsc STATUS,C ; If W less than A (C=1) --> only add 30h
  goto Add_W_30  
Add_W_37 movlw 0x37
  goto Hex_cont 
Add_W_30 movlw 0x30
Hex_cont addwf Hex_Bfr,W ; The correct ASCII code for this char !!
   return
;
;*******************************************************************
;* SendCmd - Sends command to LCD                                  *
;* This routine splits the command into the upper and lower        * 
;* nibbles and sends them to the LCD, upper nibble first.          *
;*******************************************************************
SendCmd
  banksel Byte
  movwf Byte  ; Save WREG in Byte variable
  call Delay_1MS
  swapf Byte,W  ; Send upper nibble first
  andlw 0x0f
  movwf LCD_DATA
  bcf LCD_CNTL,RS ; Clear for command
  bsf LCD_CNTL,E ; Clock nibble into LCD
  bcf LCD_CNTL,E
  movf Byte,W  ; Write lower nibble last
Send_4bit andlw 0x0f
  movwf LCD_DATA
  bcf LCD_CNTL,RS ; Clear for command

  bsf LCD_CNTL,E ; CLOCk nibble into LCD
  bcf LCD_CNTL,E
  return
;
;*******************************************************************
;* clrLCD - Clear the contents of the LCD                          *
;*******************************************************************
clrLCD
  movlw CLR_DISP ; Send the command to clear display
  call SendCmd
  return
;
;*******************************************************************
;* L1homeLCD - Moves the cursor to home position on Line 1         *
;*******************************************************************
L1homeLCD
  movlw DD_RAM_ADDR|0x00 ; Send command to move cursor to 
  call SendCmd   ; home position on line 1
  return


;*******************************************************************
;* L2homeLCD - Moves the cursor to home position on Line 2         *
;*******************************************************************
L2homeLCD
  movlw DD_RAM_ADDR|0x28 ; Send command to move cursor to
  call SendCmd   ; home position on line 2
  return


;*******************************************************************
;* Delay - GenerIC LCD delay  (1.024mS @ 4MHz)                     *
;* Since the microcontroller CAN not read the busy flag of the     *
;* LCD, a specific delay needs to be executed between writes to    *
;* the LCD.                                                        *
;*******************************************************************
Delay_1MS    ; 2 cycles for call
  clrf Count  ; 1 cycle to clear counter variable
Dloop
  nop
  decfsz Count,F  ; These two instructions provide a
  goto Dloop  ; (256 * 3) -1 cycle count
  return   ; 2 cycles for return
;
;*******************************************************************
;*       Delay - 1mS base delay        *
;*       input : W Reg.                                            *
;*                                                                 *
;*******************************************************************
Delay_MS
  movwf Count1
;
DLop1  call Delay_1MS
  decfsz Count1,F
  goto DLop1
  return
;
  END


推荐阅读

史海拾趣

科通(COMTEK)公司的发展小趣事

面对快速变化的电子行业市场,科通技术始终坚持以技术创新为驱动,不断推动公司的转型升级。公司加大在研发方面的投入,积极引进先进的技术和设备,提升产品的技术含量和附加值。同时,科通技术还不断拓展业务领域,从单一的元器件分销逐渐发展到提供全方位的技术整合方案和应用方案,为客户提供更加全面、专业的服务。

苏州锋驰(Feng)公司的发展小趣事
在科研和实验过程中,为各种实验装置提供稳定的电流输出。
Fillfactory Nv公司的发展小趣事

2015年,FIDELIX迎来了一个重要的转折点。在这一年,东芯半导体有限公司(以下简称“东芯半导体”)正式收购了FIDELIX 25.3%的股权,成为其第一大股东及实际控制人。这一收购标志着FIDELIX开始进入一个新的发展阶段。

通过与东芯半导体的合作,FIDELIX获得了更多的资金支持和市场资源。东芯半导体是一家专注于中小容量存储芯片研发、设计和销售的中国企业,在半导体领域拥有丰富的经验和资源。双方的合作不仅为FIDELIX带来了更多的发展机会,同时也加速了FIDELIX在国际市场上的扩张步伐。

在上述两个故事的基础上,可以根据FIDELIX公司的具体发展历程、重要事件、技术创新、市场策略等方面进行进一步的拓展和补充,以形成完整、详细的故事内容。

Hirose公司的发展小趣事

FIDELIX公司成立于1990年,是一家专注于存储芯片研发与销售的韩国企业。在公司成立初期,FIDELIX凭借对技术的深入研究和对市场的敏锐洞察,成功推出了多款性能优越的NAND FLASH(闪存)和SDR/DDR(单/双数率同步动态存储器)等存储芯片产品。这些产品不仅在韩国市场上获得了良好的口碑,同时也开始逐步进入国际市场。

随着技术的不断进步和市场的不断扩大,FIDELIX逐渐在韩国存储芯片领域崭露头角。公司不断投入研发资金,加强技术创新,努力提升产品的性能和品质。同时,FIDELIX也积极拓展销售渠道,与多家国内外知名厂商建立了合作关系,为公司的持续发展奠定了坚实的基础。

德力康(DLK)公司的发展小趣事

随着电子行业的不断发展和变革,DLK公司也面临着转型升级的压力。为了适应市场需求的变化,DLK公司开始加快转型升级的步伐。一方面,公司加强了对新能源汽车、物联网等新兴领域的研究和开发;另一方面,公司积极探索智能制造、工业互联网等新技术在连接器生产中的应用。通过转型升级,DLK公司不仅提高了生产效率和产品质量,而且增强了企业的竞争力和可持续发展能力。

无锡友达公司的发展小趣事

无锡友达深知技术创新的重要性,因此不断加大对研发团队的投入。公司拥有一支经验丰富、技术实力雄厚的研发团队,以及一流的成套设计工具和测试设备。这些团队和工具为公司开发具有自主知识产权的产品提供了有力保障。在数模混合信号处理领域,无锡友达拥有自己的系统设计体系和核心技术,产品研发技术和量产能力处于国内前列。

问答坊 | AI 解惑

windows ce5.0与MBCS之间的问题

在编译windows ce5.0的程序时,字符集采用的是MBCS,但是在编译的时候出现了一个错误: 1>D:\\Program Files\\Microsoft Visual Studio 8\\VC\\ce\\atlmfc\\include\\afxv_w32.h(227) : fatal error C1083: Cannot open include file: \'mbctype.h ...…

查看全部问答>

定时器捕获与匹配冲突

我用CORTEX-M3内核,用TIM1做捕获中断,TIM3做匹配更新中断,但是发现TIM1的捕获必须在TIM3匹配中断禁止后才有用,有没有人了解的…

查看全部问答>

wince上, 存储内存 <--> 程序内存 如何理解?

wince上, 控制面板->系统->内存(系统属性) wince上, 存储内存 程序内存 如何理解? 我的程序运行某个功能时,存储内存越来越少,是什么原因? …

查看全部问答>

延时电路问题

我很菜,现在要用到一个延时5S到30S可调的电路,用这个电路(附件),R1,R2用的是可调的电位器。可是只有积分的作用没有起到延时的作用,望大家多多指点。 谢谢!…

查看全部问答>

wince下计算两个日期差!

比如一个输入  2007-10-21   ,另一个输入   2008-11-12        如何计算这两个input的差值是多少秒 精确到秒 谢谢…

查看全部问答>

CF卡启动问题

请问各位大虾: 这两天在PC机上做CF卡启动,按照网上查的资料修改了相关文件后生成了bootrom和vxworks文件,启动行设置为 ata=0,0(0,0)target:/ata0/vxWorks h=10.21.110.16 e=10.21.110.30 u=TargetUser pw=vxworks 然后在DOS下vxsys C:(C为 ...…

查看全部问答>

探讨下关于不等电位的MOS管驱动

如图,请大家一起他们探讨下关于这种不等电位的MOS管驱动有哪些办法,不用专门芯片,谢谢 …

查看全部问答>

恳请武林高手出山指点一二

各位大虾:            小弟最近在学习uc/os ii 在arm7 ADuC7026上的移植,想第一步实现操作系统下的简单控制,单任务,比方说LED闪烁控制,希望各位大牛门能帮忙指点一二,帮忙详细讲解一下整 ...…

查看全部问答>

自行车测速、里程计图/程序

自行车测速、里程计图/程序…

查看全部问答>

今天真是悲惨的一天啊

今天真是悲惨的一天啊 最近想A8开发板都想疯了 公司没法上网,请朋友帮忙抢购 结果呢,没抢到,她不会操作..... 啊啊啊!我的A8啊 管理员啊,管理员…

查看全部问答>