URL
https://opencores.org/ocsvn/mcip_open/mcip_open/trunk
Subversion Repositories mcip_open
[/] [mcip_open/] [trunk/] [Hi_MCIPopen.ASM] - Rev 5
Go to most recent revision | Compare with Previous | Blame | View Log
;******************************************************************************
; *
; Filename: Hi_MCIPopen.asm *
; Description: ASM program for MCIPopen implementation example *
; Date: 07/25/2015 *
; File Version: 1 *
; Tool: MPLAB IDE v8.83 *
; *
; Author: Ibrahim MEZZAH *
; Company: Ferhat Abbas University - Algeria *
; *
;******************************************************************************
; *
; Files Required: P18F4410.INC *
; *
;******************************************************************************
LIST P=18F4410 ;directive to define processor
#include <P18F4410.INC> ;processor specific variable definitions
; Oscillator Selection:
CONFIG OSC = LP ;LP
; LCD defines /////////////////////////////////////////
#define LCD_DATA_PRT 0xF8B ;/*PRTC*/
#define LCD_DATA_PORT 0x8B
#define LCD_TRIS_DATA_PORT 0x94
#define LCD_INST_PORT 0x8C ;/*PRTD*/
#define LCD_TRIS_INST_PORT 0x95
#define RW_PIN 5 ;/* PORT for RW */
#define RS_PIN 6 ;/* PORT for RS */
#define E_PIN 7 ;/* PORT for E */
#define FOUR_BIT 0x28 ;0b00101000
#define CLEAR 0x01 ;0b00000001
#define CURSOR_HOME 0x02 ;0b00000010
#define MODE_SET 0x06 ;0b00000110
#define DISPLAY_ON_C 0x0e ;0b00001110
#define DISPLAY_ON_B 0x0f ;0b00001111
#define DISPLAY_ON 0x0c ;0b00001100
#define DISPLAY_OFF 0x08 ;0b00001000
#define SHIFT_D_R 0x1c ;0b00011100
#define SHIFT_D_L 0x18 ;0b00011000
#define SHIFT_C_R 0x14 ;0b00010100
#define SHIFT_C_L 0x10 ;0b00010000
#define access 0
CBLOCK 0x080
WREG_TEMP1 ;variable used for context saving
STATUS_TEMP1 ;variable used for context saving
BSR_TEMP1 ;variable used for context saving
WREG_TEMP2 ;variable used for context saving
STATUS_TEMP2 ;variable used for context saving
BSR_TEMP2 ;variable used for context saving
WREG_TEMP3 ;variable used for context saving
STATUS_TEMP3 ;variable used for context saving
BSR_TEMP3 ;variable used for context saving
WREG_TEMP4 ;variable used for context saving
STATUS_TEMP4 ;variable used for context saving
BSR_TEMP4 ;variable used for context saving
ENDC
CBLOCK 0x009 ;variables in access RAM
e1
e2
e3
e4
LCD_command
LCD_data
ENDC
;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.
ORG 0x0000
goto Main ;go to start of main code
Main:
;------------------------------------------------------------------------------
; I/O ports configuration
;------------------------------------------------------------------------------
MOVLW 0x0f
MOVWF LCD_TRIS_DATA_PORT,0
CLRF LCD_INST_PORT,0
MOVLW 0x1f
MOVWF LCD_TRIS_INST_PORT,0
MOVLW 0x0f
CLRF LATA
MOVWF TRISA
CLRF TRISB
;------------------------------------------------------------------------------
; LCD Initialisation
;------------------------------------------------------------------------------
MOVLW 0x30
MOVWF LCD_DATA_PORT,0
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
CALL Delay1_6ms
CALL Delay1_6ms
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
CALL Delay42us
CALL Delay42us
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
CALL Delay42us
CALL Delay42us
MOVLW 0x20
MOVWF LCD_DATA_PORT,0
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
CALL Delay42us
CALL Delay42us
MOVLW FOUR_BIT
MOVWF LCD_command,access
CALL Command
CALL Delay42us
CALL Delay42us
MOVLW DISPLAY_OFF
MOVWF LCD_command,access
CALL Command
CALL Delay42us
CALL Delay42us
MOVLW DISPLAY_ON
MOVWF LCD_command,access
CALL Command
CALL Delay42us
CALL Delay42us
MOVLW MODE_SET
MOVWF LCD_command,access
CALL Command
CALL Delay42us
CALL Delay42us
MOVLW CLEAR
MOVWF LCD_command,access
CALL Command
CALL Delay1_6ms
CALL Delay1_6ms
;------------------------------------------------------------------------------
; END LCD Initialisation
;------------------------------------------------------------------------------
; Displaying "Hello MCIP!"
MOVLW 0x03
MOVWF LCD_data,access
CALL Set_address
CALL Delay42us
MOVLW 'H'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'e'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'l'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'l'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'o'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW ' '
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'M'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'C'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'I'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 'P'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW '!'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
;--------------------
MOVLW 0x53
MOVWF LCD_data,access
CALL Set_address
CALL Delay42us
MOVLW '<'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW '<'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW 0x63
MOVWF LCD_data,access
CALL Set_address
CALL Delay42us
MOVLW '<'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
MOVLW '<'
MOVWF LCD_data,access
CALL Display
CALL Delay42us
;----------------------
; ~ 2second delay
MOVLW 0x22
MOVWF e4,access
loop21:
CALL Delay58ms
DECFSZ e4,1,access
BRA loop21
MOVLW 0x80
MOVWF LATB
looplooop:
RLNCF LATB,1,0
MOVLW SHIFT_D_L
MOVWF LCD_command,access
CALL Command
MOVLW 0x0f
ANDWF PORTA,0,0
MOVWF e4,0
INCF e4,1,0
loop_3x58ms:
CALL Delay58ms
;CALL Delay58ms
DECF e4,1,0
TSTFSZ e4,0
BRA loop_3x58ms
BRA looplooop
; Fuctions:
;---------------------------------
; Delay 42us *********************
Delay42us:
;save working registers
movff STATUS,STATUS_TEMP1
movff WREG,WREG_TEMP1
movff BSR,BSR_TEMP1
MOVLW 0xAC
MOVWF e1,access
loop10:
INCFSZ e1,1,access
BRA loop10
;restore working registers
movff BSR_TEMP1,BSR
movff WREG_TEMP1,WREG
movff STATUS_TEMP1,STATUS
RETURN
;******** end Delay 40us **********
;----------------------------------
;---------------------------------
; Delay 1.6ms ********************
Delay1_6ms:
;save working registers
movff STATUS,STATUS_TEMP2
movff WREG,WREG_TEMP2
movff BSR,BSR_TEMP2
MOVLW 0x25
MOVWF e2,access
loop3:
CALL Delay42us
DECFSZ e2,1,access
BRA loop3
;restore working registers
movff BSR_TEMP2,BSR
movff WREG_TEMP2,WREG
movff STATUS_TEMP2,STATUS
RETURN
;******** end Delay1.6ms **********
;----------------------------------
;---------------------------------
; Delay 58ms *********************
Delay58ms:
;save working registers
movff STATUS,STATUS_TEMP3
movff WREG,WREG_TEMP3
movff BSR,BSR_TEMP3
MOVLW 0x24
MOVWF e3,access
loop4:
CALL Delay1_6ms
DECFSZ e3,1,access
BRA loop4
;restore working registers
movff BSR_TEMP3,BSR
movff WREG_TEMP3,WREG
movff STATUS_TEMP3,STATUS
RETURN
;******** end Delay 58ms **********
;----------------------------------
;----------------------------------
; send a command to the LCD *******
Command:
;save working registers
movff STATUS,STATUS_TEMP4
movff WREG,WREG_TEMP4
movff BSR,BSR_TEMP4
MOVFF LCD_command,LCD_DATA_PRT
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
SWAPF LCD_DATA_PORT,1,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
;restore working registers
movff BSR_TEMP4,BSR
movff WREG_TEMP4,WREG
movff STATUS_TEMP4,STATUS
RETURN
;****** end send command **********
;----------------------------------
;----------------------------------
; send data to the LCD ************
Display:
;save working registers
movff STATUS,STATUS_TEMP4
movff WREG,WREG_TEMP4
movff BSR,BSR_TEMP4
MOVFF LCD_data,LCD_DATA_PRT
BSF LCD_INST_PORT,RS_PIN,0
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
SWAPF LCD_DATA_PORT,1,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
BCF LCD_INST_PORT,RS_PIN,0
;restore working registers
movff BSR_TEMP4,BSR
movff WREG_TEMP4,WREG
movff STATUS_TEMP4,STATUS
RETURN
;******** end send data ***********
;----------------------------------
;----------------------------------
; Set an address to the LCD *******
Set_address:
;save working registers
movff STATUS,STATUS_TEMP4
movff WREG,WREG_TEMP4
movff BSR,BSR_TEMP4
MOVLW 0x80
IORWF LCD_data,1,access
MOVFF LCD_data,LCD_DATA_PRT
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
SWAPF LCD_DATA_PORT,1,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF LCD_INST_PORT,E_PIN,0
NOP
NOP
NOP
BCF LCD_INST_PORT,E_PIN,0
;restore working registers
movff BSR_TEMP4,BSR
movff WREG_TEMP4,WREG
movff STATUS_TEMP4,STATUS
RETURN
;******** end set address *********
;----------------------------------
;******************************************************************************
;End of program
END
Go to most recent revision | Compare with Previous | Blame | View Log