ATUS_process id 1840),d,ID_TIMER,10,NULL);unsignedshortmid;

 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
dm9000驱动程序
下载积分:300
内容提示:dm9000驱动程序 dm9000驱动程序 dm9000驱动程序 dm9000驱动程序
文档格式:PDF|
浏览次数:16|
上传日期: 11:29:10|
文档星级:
该用户还上传了这些文档
dm9000驱动程序
官方公共微信LCD interfacing with a PIC - TUTORIAL -
Results 1 to 12 of 12
Full Member level 6
pic lcd tutorial
I've see that many people have trouble about LCD interfacing, I've just finish to develop a library to do all the things needed to drive a HD44780 LCD controller based display with a PIC. My application is able to work with 4 bit interface (in order to save 4 pin of the microcontroller) and also isn't restricted to some PIC, just change the pin assignement on the header file and all is done.
This design was originally compiled with Hi-Tech for a PIC16F870 (20 MHz clock) but there is no restriction about what type of PIC you can use, simply change the pin assignement as I'll show later.
There are only three file:
- lcddisp.c (main file - just to show how to use the library)
- lcd-lib.c (the code to drive the LCD)
- lcd-lib.h (pin assignement)
Starting with the main file we've at first the inclusion of the header file regarding the microcontroller pin assignement:
Code: #include &pic.h&
#include &stdio.h&
#include &lcd-lib.h&
// Pin definition for the LCD
Open the lcd-lib.h file, here below you can find the pin declaration for the Hi-Tech compiler, if you use another type of compiler simply change the pin syntax, just only a things, don't touch the pin name (RS, RW, EN, DB4, DB5, DB6, DB7) because these will be referred from the LCD routine inside the lcd-lib.c file:
Code: // -------------------------------------------
// LCD type
// -------------------------------------------
#define MAXPOSX
#define MAXPOSY
// -------------------------------------------
// Definition of the LCD uP pin (Hi-Tech compiler)
// -------------------------------------------
static volatile bit RS @
(unsigned)&PORTA*8+0;
static volatile bit RW @
(unsigned)&PORTA*8+1;
static volatile bit EN @
(unsigned)&PORTA*8+2;
static volatile bit DB4 @ (unsigned)&PORTB*8+1;
static volatile bit DB5 @ (unsigned)&PORTB*8+2;
static volatile bit DB6 @ (unsigned)&PORTB*8+3;
static volatile bit DB7 @ (unsigned)&PORTB*8+4;
Now you've available these functions:
Code: void GenDelay(int);// Generic delay
void LongDelay(long); // Long generic delay
void LCDInit(void); // LCD init routine
void ClearDisplay(void);// Clear the LCD display
void CursorAtHome(void);// Set cursor to home position
void Printxy(unsigned char, unsigned char, unsigned char); // Print a char
If you are using a different compiler or other frequency clock simply change the delay routine to meet your need, just take care about the timing that I've written as remark into the source code.
About the display there is no restriction, the only things is about the controller it must be a HD44780 or compatible.
I've also attached a pic of the connection (the 2kOhm trimmer on the right of the connector is used to set the LCD contrast), anyway here the display connector signal name:
Pin 1: Vss (0 V)
Pin 2: Vcc (+5V)
Pin 3: Vee (contrast, just use a simple 2kOhm trimmer from Vcc to Vss, cursor to Vee)
Pin 5: R/W
Pin 7: DB0 (not used for 4-bit interface)
Pin 8: DB1 (not used for 4-bit interface)
Pin 9: DB2 (not used for 4-bit interface)
Pin 10: DB3 (not used for 4-bit interface)
Pin 11: DB4 (used for 4-bit interface)
Pin 12: DB5 (used for 4-bit interface)
Pin 13: DB6 (used for 4-bit interface)
Pin 14: DB7 (used for 4-bit interface)
Pin 15: Led anode (+)
Pin 16: Led katode (-)
I've not used the led for back illumination, if you like to use it connect the Pin 15 trough a 680Ohm resistor to the +5V and the Pin 16 to the 0V.
Hope this can help a bit.
Member level 2
temp lcd tutorial
Could I have the assmebly source code for this????
Best regards
1 members found this post helpful.
Full Member level 6
Re: LCD interfacing with a PIC - TUTORIAL -
I've coded it in C but I think is very very easy translate the routine inside the lcd-lib.c file in assembly. Let me know if you need help, at now I've no more time but into the next days I can try to make the translate to asm.
To help you in a fast way I've attached the asm listing, this is the compilation result then you can make the change in easy way.
C:\Temp\PIC_LCD\lcd-lib.c
------------------------------------------------------------------
void GenDelay(int);
// Funzione per ritrado generico (& 1 secondo)
void LongDelay(long);
// Funzione per ritrado generico (& 1 secondo)
void LCDInit(void);
void ClearDisplay(void);
// Cancella il contenuto dedl display
void CursorAtHome(void);
// Posiziona il cursore nella posizione di Home
void Printxy(unsigned char, unsigned char, unsigned char);
// Visualizza un carattere sul display
// -----------------------------------------------------------------------
// Purpose
: Generic delay (us range)
: Powermos
// Date creazione
: 25/09/2008
// -----------------------------------------------------------------------
void GenDelay(int DelayPar)
asm(&clrwdt&);
if (DelayPar &= 0)
BCF 0x3, 0x5
BCF 0x3, 0x6
BTFSC 0x29, 0x7
DelayPar--;
MOVF 0x28, F
BTFSC 0x3, 0x2
DECF 0x29, F
DECF 0x28, F
goto Loop1;
GOTO 0x4d4
// -----------------------------------------------------------------------
// Purpose
: Generic delay (ms range)
: Powermos
// Date creazione
: 25/09/2008
// -----------------------------------------------------------------------
void LongDelay(long DelayExt)
MOVLW 0x20
long DelayInt = 800;
MOVWF 0x27
MOVWF 0x28
if (DelayExt &=0)
GOTO 0x545
BTFSC 0x26, 0x7
GOTO 0x52a
asm(&clrwdt&);
if (DelayInt &= 0)
BTFSS 0x2a, 0x7
GOTO 0x518
DelayInt--;
MOVWF 0x70
SUBWF 0x27, F
MOVF 0x71, W
BTFSS 0x3, 0
INCFSZ 0x71, W
SUBWF 0x28, F
MOVF 0x72, W
BTFSS 0x3, 0
INCFSZ 0x72, W
SUBWF 0x29, F
MOVF 0x73, W
BTFSS 0x3, 0
INCF 0x73, W
SUBWF 0x2a, F
goto LoopI
DelayInt = 800;
MOVLW 0x20
MOVWF 0x27
MOVWF 0x28
DelayExt--;
MOVWF 0x70
SUBWF 0x23, F
MOVF 0x71, W
BTFSS 0x3, 0
INCFSZ 0x71, W
SUBWF 0x24, F
MOVF 0x72, W
BTFSS 0x3, 0
INCFSZ 0x72, W
SUBWF 0x25, F
MOVF 0x73, W
BTFSS 0x3, 0
INCF 0x73, W
SUBWF 0x26, F
goto LoopE
// -----------------------------------------------------------------------
// Purpose
: LCD initialization with 4 bit interface
: Powermos
// Date creazione
: 25/09/2008
// -----------------------------------------------------------------------
void LCDInit(void)
// Code 0x03
BCF 0x5, 0
BCF 0x5, 0x1
BSF 0x6, 0x1
BSF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
for (i=0; i&8; i++)
INCF 0x23, F
SUBWF 0x23, W
BTFSS 0x3, 0
GOTO 0x648
GenDelay(255); // Time delay 5 ms minimum
MOVLW 0xff
MOVWF 0x28
CALL 0x4d4
// Code 0x03
BCF 0x5, 0
BCF 0x5, 0x1
BSF 0x6, 0x1
BSF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(60); // Time dalay 160 us minimum
MOVLW 0x3c
MOVWF 0x28
CALL 0x4d4
// Code 0x03
BCF 0x5, 0
BCF 0x5, 0x1
BSF 0x6, 0x1
BSF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(60); // Time dalay 160 us minimum
MOVLW 0x3c
MOVWF 0x28
CALL 0x4d4
// Function Set (Code 0x02)
BCF 0x5, 0
BCF 0x5, 0x1
BCF 0x6, 0x1
BSF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
MOVLW 0x14
MOVWF 0x28
CALL 0x4d4
// Function Set (D,N,F)
BCF 0x5, 0
BCF 0x5, 0x1
= 0; // D=0 set the 4-bit interface
BCF 0x6, 0x1
BSF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
BCF 0x6, 0x1
BCF 0x6, 0x2
DB6 = 0; // F=0 font
BCF 0x6, 0x3
= 1; // N=1 display 2 linee
BSF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
MOVLW 0x14
MOVWF 0x28
CALL 0x4d4
// Display OFF
BCF 0x5, 0
BCF 0x5, 0x1
BCF 0x6, 0x1
BCF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
BCF 0x6, 0x1
BCF 0x6, 0x2
BCF 0x6, 0x3
BSF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
MOVLW 0x14
MOVWF 0x28
CALL 0x4d4
// Display ON
BCF 0x5, 0
BCF 0x5, 0x1
BCF 0x6, 0x1
BCF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
= 0; // B (Cursor blinking ON= 1, OFF=0)
BCF 0x6, 0x1
= 0; // C (Cursor ON=1, OFF=0)
BCF 0x6, 0x2
DB6 = 1; // D (Display ON=1, OFF=0)
BSF 0x6, 0x3
BSF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
MOVLW 0x14
MOVWF 0x28
CALL 0x4d4
// Entry mode set
BCF 0x5, 0
BCF 0x5, 0x1
BCF 0x6, 0x1
BCF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
= 0; // S=0
BCF 0x6, 0x1
= 1; // ID=1
BSF 0x6, 0x2
BSF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
MOVLW 0x14
MOVWF 0x28
CALL 0x4d4
ClearDisplay();
GOTO 0x4eb
// -----------------------------------------------------------------------
// Purpose
: Cancella il contenuto dedl display
: Powermos
// Date creazione
: 25/09/2008
// -----------------------------------------------------------------------
void ClearDisplay(void)
// Clear Display
BCF 0x5, 0
BCF 0x5, 0x1
BCF 0x6, 0x1
BCF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
BSF 0x6, 0x1
BCF 0x6, 0x2
BCF 0x6, 0x3
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
for (i=0; i&8; i++)
INCF 0x24, F
SUBWF 0x24, W
BTFSC 0x3, 0
GOTO 0x505
GenDelay(255); // Wait for 5 ms min
MOVLW 0xff
// -----------------------------------------------------------------------
// Purpose
: set the cursor position to home
: Powermos
// Date creazione
: 25/09/2008
// -----------------------------------------------------------------------
void CursorAtHome(void)
unsigned char Position = 0;
Position = Position | 0b; // Set DB7 to 1
BSF 0x23, 0x7
BCF 0x5, 0
BCF 0x5, 0x1
= ((Position & 0b) == 16) ? 1 : 0;
BTFSS 0x23, 0x4
GOTO 0x551
BSF 0x6, 0x1
GOTO 0x552
BCF 0x6, 0x1
= ((Position & 0b) == 32) ? 1 : 0;
BCF 0x3, 0x5
BCF 0x3, 0x6
BTFSS 0x23, 0x5
GOTO 0x558
BSF 0x6, 0x2
GOTO 0x559
BCF 0x6, 0x2
= ((Position & 0b) == 64) ? 1 : 0;
BTFSS 0x23, 0x6
GOTO 0x55d
BSF 0x6, 0x3
GOTO 0x55e
BCF 0x6, 0x3
= ((Position & 0b) == 128) ? 1 : 0;
BTFSS 0x23, 0x7
GOTO 0x562
BSF 0x6, 0x4
GOTO 0x563
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
= ((Position & 0b) == 1) ? 1 : 0;
BTFSS 0x23, 0
GOTO 0x56e
BSF 0x6, 0x1
GOTO 0x56f
BCF 0x6, 0x1
= ((Position & 0b) == 2) ? 1 : 0;
BTFSS 0x23, 0x1
GOTO 0x573
BSF 0x6, 0x2
GOTO 0x574
BCF 0x6, 0x2
= ((Position & 0b) == 4) ? 1 : 0;
BTFSS 0x23, 0x2
GOTO 0x578
BSF 0x6, 0x3
GOTO 0x579
BCF 0x6, 0x3
= ((Position & 0b) == 8) ? 1 : 0;
BTFSS 0x23, 0x3
GOTO 0x57d
BSF 0x6, 0x4
GOTO 0x57e
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait approx 59 us (minimum requested is 37 us)
MOVLW 0x14
// -----------------------------------------------------------------------
// Purpose
: show a char on the LCD
X position, Y position, char code to show
: Powermos
// Date creazione
: 25/09/2008
// -----------------------------------------------------------------------
void Printxy(unsigned char Xpos, unsigned char Ypos, unsigned char CharToDisp)
MOVWF 0x25
int Position = 0;
unsigned char CharLo;
unsigned char CharHi;
// Check if X and Y are valid for the current display
if (Xpos & MAXPOSX)
MOVLW 0x11
SUBWF 0x25, W
BTFSS 0x3, 0
GOTO 0x593
Xpos = MAXPOSX;
MOVLW 0x10
MOVWF 0x25
if (Ypos & MAXPOSY)
SUBWF 0x23, W
BTFSS 0x3, 0
GOTO 0x5a9
Ypos = MAXPOSY;
MOVWF 0x23
// Calculate the DDRAM address
switch (Ypos)
GOTO 0x5a9
MOVF 0x23, W
BTFSC 0x3, 0x2
GOTO 0x5b6
BTFSC 0x3, 0x2
GOTO 0x59a
BTFSC 0x3, 0x2
GOTO 0x59c
BTFSC 0x3, 0x2
GOTO 0x59e
case 1 : Position =
case 2 : Position = 64 + X
MOVLW 0x40
GOTO 0x59f
case 3 : Position = 20 + X
MOVLW 0x14
GOTO 0x59f
case 4 : Position = 84 + X
MOVLW 0x54
MOVWF 0x70
MOVF 0x25, W
ADDWF 0x70, W
MOVWF 0x26
MOVF 0x71, W
BTFSC 0x3, 0
INCF 0x71, W
MOVWF 0x27
GOTO 0x5b9
default: Position =
MOVF 0x25, W
MOVWF 0x26
// Set the cursor position (DDRAM address)
Position = Position | 0b; // Set DB7 to 1
BSF 0x26, 0x7
BCF 0x5, 0
BCF 0x5, 0x1
= ((Position & 0b) == 16) ? 1 : 0;
BTFSS 0x26, 0x4
GOTO 0x5c0
BSF 0x6, 0x1
GOTO 0x5c1
BCF 0x6, 0x1
= ((Position & 0b) == 32) ? 1 : 0;
BCF 0x3, 0x5
BCF 0x3, 0x6
BTFSS 0x26, 0x5
GOTO 0x5c7
BSF 0x6, 0x2
GOTO 0x5c8
BCF 0x6, 0x2
= ((Position & 0b) == 64) ? 1 : 0;
BTFSS 0x26, 0x6
GOTO 0x5cc
BSF 0x6, 0x3
GOTO 0x5cd
BCF 0x6, 0x3
= ((Position & 0b) == 128) ? 1 : 0;
BTFSS 0x26, 0x7
GOTO 0x5d1
BSF 0x6, 0x4
GOTO 0x5d2
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
= ((Position & 0b) == 1) ? 1 : 0;
BTFSS 0x26, 0
GOTO 0x5dd
BSF 0x6, 0x1
GOTO 0x5de
BCF 0x6, 0x1
= ((Position & 0b) == 2) ? 1 : 0;
BTFSS 0x26, 0x1
GOTO 0x5e2
BSF 0x6, 0x2
GOTO 0x5e3
BCF 0x6, 0x2
= ((Position & 0b) == 4) ? 1 : 0;
BTFSS 0x26, 0x2
GOTO 0x5e7
BSF 0x6, 0x3
GOTO 0x5e8
BCF 0x6, 0x3
= ((Position & 0b) == 8) ? 1 : 0;
BTFSS 0x26, 0x3
GOTO 0x5ec
BSF 0x6, 0x4
GOTO 0x5ed
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait approx 59 us (minimum requested is 37 us)
MOVLW 0x14
MOVWF 0x28
CALL 0x4d4
// Show the char on the LCD
BSF 0x5, 0
BCF 0x5, 0x1
= ((CharToDisp & 0b) == 16) ? 1 : 0;
BTFSS 0x24, 0x4
GOTO 0x5fe
BSF 0x6, 0x1
GOTO 0x5ff
BCF 0x6, 0x1
= ((CharToDisp & 0b) == 32) ? 1 : 0;
BCF 0x3, 0x5
BCF 0x3, 0x6
BTFSS 0x24, 0x5
GOTO 0x605
BSF 0x6, 0x2
GOTO 0x606
BCF 0x6, 0x2
= ((CharToDisp & 0b) == 64) ? 1 : 0;
BTFSS 0x24, 0x6
GOTO 0x60a
BSF 0x6, 0x3
GOTO 0x60b
BCF 0x6, 0x3
= ((CharToDisp & 0b) == 128) ? 1 : 0;
BTFSS 0x24, 0x7
GOTO 0x60f
BSF 0x6, 0x4
GOTO 0x610
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
= ((CharToDisp & 0b) == 1) ? 1 : 0;
BTFSS 0x24, 0
GOTO 0x61b
BSF 0x6, 0x1
GOTO 0x61c
BCF 0x6, 0x1
= ((CharToDisp & 0b) == 2) ? 1 : 0;
BTFSS 0x24, 0x1
GOTO 0x620
BSF 0x6, 0x2
GOTO 0x621
BCF 0x6, 0x2
= ((CharToDisp & 0b) == 4) ? 1 : 0;
BTFSS 0x24, 0x2
GOTO 0x625
BSF 0x6, 0x3
GOTO 0x626
BCF 0x6, 0x3
= ((CharToDisp & 0b) == 8) ? 1 : 0;
BTFSS 0x24, 0x3
GOTO 0x62a
BSF 0x6, 0x4
GOTO 0x62b
BCF 0x6, 0x4
BSF 0x5, 0x2
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
asm(&nop&);
BCF 0x5, 0x2
GenDelay(20); // Wait approx 59 us (minimum requested is 37 us)
MOVLW 0x14
MOVWF 0x28
CALL 0x4d4
BCF 0x5, 0
BCF 0x5, 0x1
C:\Temp\PIC_LCD\lcddisp.c
------------------------------------------------------------------
#include &pic.h&
#include &stdio.h&
#include &lcd-lib.h&
// Pin definition file for the LCD
// ---------------------------------------------------------------------------
: LCDDISP.PJT
// Purpose : LCD display with PIC16F870 (LCD 2x16) 4 bit interface
: Powermos
: 25/09/2008
// General : Fosc = 20.000 MHz, C1=C2=33 pF, Rosc2 = 10 Ohm, Hi-Tech compiler
// ---------------------------------------------------------------------------
0 = RS (Data / Instruction register select)
1 = RW (Read / Write )
2 = EN (Enable signal, start data read / write)
3 = NOT USED (Input)
4 = NOT USED (Input)
5 = NOT USED (Input)
// PORTB (4 bit data bus display LCD)
0 = NOT USED (Input)
1 = NOT USED (Input)
2 = NOT USED (Input)
3 = NOT USED (Input)
0 = NOT USED (Input)
1 = NOT USED (Input)
2 = NOT USED (Input)
3 = NOT USED (Input)
4 = NOT USED (Input)
5 = NOT USED (Input)
6 = NOT USED (Input)
7 = NOT USED (Input)
// ---------------------------------------------------------------------------
__CONFIG(0x3F72);
__IDLOC(FFFF); // ID0 = 0F, ID1 = 0F, ID2 = 0F, ID3 = 0F
// ===========================================================================
// GLOBAL VARIABLE DEFINITION
// ===========================================================================
unsigned char SWVersion[] = &Ver. 1.0&;
unsigned char SWDate[]
= &25/09/2008&;
// ===========================================================================
// FUNCTIONS DECLARATION
// ===========================================================================
void HardwareInit(void);
// Inizializzazione periferiche hardware
void interrupt InterruptServiceRoutine(void);
// Funzione per gestione interrupt
// ===========================================================================
// FUNCTIONS DEFINITION
// ===========================================================================
HardwareInit(void)
// -----------------------------------------------------------------------
// uP hardware initialization
// -----------------------------------------------------------------------
// ADC off, all digital I/O
BCF 0x1f, 0
ADCON1 = 0b;
BSF 0x3, 0x5
MOVWF 0x1f
// PORT direction register
TRISA = 0b;
MOVLW 0xf8
TRISB = 0b;
MOVLW 0xe1
TRISC = 0b;
MOVLW 0xff
BCF 0x3, 0x5
// -----------------------------------------------------------------------
// Interrupt handler
// -----------------------------------------------------------------------
void interrupt InterruptServiceRoutine(void)
BCF 0xb, 0x7
// ...........
BSF 0xb, 0x7
BCF 0x3, 0x6
// -----------------------------------------------------------------------
// Include the LCD source code
// -----------------------------------------------------------------------
#include &lcd-lib.c&
// ===========================================================================
// ===========================================================================
void main(void)
BCF 0x3, 0x5
unsigned char i = 0;
BCF 0x3, 0x6
unsigned char Xpos = 0;
unsigned char Ypos = 0;
// Init the uP hardware
HardwareInit();
CALL 0x4de
// Power-up time (almeno 50 ms)
LongDelay(10);
MOVWF 0x23
CALL 0x50f
// Must be the first function called!!!!
LCDInit();
CALL 0x639
// Show the software release version
MOVWF 0x20
INCF 0x21, F
for(i = 0; i &= 7; i++)
INCF 0x22, F
SUBWF 0x22, W
BTFSS 0x3, 0
GOTO 0x707
Printxy(Xpos+i, Ypos, *(SWVersion+i));
MOVF 0x21, W
MOVWF 0x23
MOVF 0x22, W
ADDLW 0x2b
BCF 0x3, 0x7
MOVWF 0x24
MOVF 0x20, W
ADDWF 0x22, W
CALL 0x589
// Show the data release
MOVWF 0x20
MOVWF 0x21
for(i = 0; i &= 9; i++)
INCF 0x22, F
SUBWF 0x22, W
BTFSS 0x3, 0
GOTO 0x71c
Printxy(Xpos+i, Ypos, *(SWDate+i));
MOVF 0x21, W
MOVWF 0x23
MOVF 0x22, W
ADDLW 0x34
BCF 0x3, 0x7
MOVWF 0x24
MOVF 0x20, W
ADDWF 0x22, W
CALL 0x589
// Wait for 2s
LongDelay(400);
MOVLW 0x90
MOVWF 0x23
MOVWF 0x24
CALL 0x50f
ClearDisplay();
CALL 0x4eb
// Write char at the specified location
Printxy(0 , 1, 'H');
INCF 0x23, F
MOVLW 0x48
MOVWF 0x24
CALL 0x589
Printxy(1 , 1, 'E');
INCF 0x23, F
MOVLW 0x45
MOVWF 0x24
CALL 0x589
Printxy(2 , 1, 'L');
INCF 0x23, F
MOVLW 0x4c
MOVWF 0x24
CALL 0x589
Printxy(3 , 1, 'L');
INCF 0x23, F
MOVLW 0x4c
MOVWF 0x24
CALL 0x589
Printxy(4 , 1, 'O');
INCF 0x23, F
MOVLW 0x4f
MOVWF 0x24
CALL 0x589
Printxy(5 , 1, ' ');
INCF 0x23, F
MOVLW 0x20
MOVWF 0x24
CALL 0x589
Printxy(6 , 1, 'W');
INCF 0x23, F
MOVLW 0x57
MOVWF 0x24
CALL 0x589
Printxy(7 , 1, 'O');
INCF 0x23, F
MOVLW 0x4f
MOVWF 0x24
CALL 0x589
Printxy(8 , 1, 'R');
INCF 0x23, F
MOVLW 0x52
MOVWF 0x24
CALL 0x589
Printxy(9, 1, 'L');
INCF 0x23, F
MOVLW 0x4c
MOVWF 0x24
CALL 0x589
Printxy(10, 1, 'D');
INCF 0x23, F
MOVLW 0x44
MOVWF 0x24
CALL 0x589
Printxy(11, 1, '!');
INCF 0x23, F
MOVLW 0x21
MOVWF 0x24
CALL 0x589
Printxy(0 , 2, 'L');
MOVWF 0x23
MOVLW 0x4c
MOVWF 0x24
CALL 0x589
Printxy(1 , 2, 'C');
MOVWF 0x23
MOVLW 0x43
MOVWF 0x24
CALL 0x589
Printxy(2 , 2, 'D');
MOVWF 0x23
MOVLW 0x44
MOVWF 0x24
CALL 0x589
Printxy(3 , 2, ' ');
MOVWF 0x23
MOVLW 0x20
MOVWF 0x24
CALL 0x589
Printxy(4 , 2, 'T');
MOVWF 0x23
MOVLW 0x54
MOVWF 0x24
CALL 0x589
Printxy(5 , 2, 'E');
MOVWF 0x23
MOVLW 0x45
MOVWF 0x24
CALL 0x589
Printxy(6 , 2, 'S');
MOVWF 0x23
MOVLW 0x53
MOVWF 0x24
CALL 0x589
Printxy(7 , 2, 'T');
MOVWF 0x23
MOVLW 0x54
MOVWF 0x24
CALL 0x589
CursorAtHome();
CALL 0x548
// Wait for 2s
LongDelay(400);
MOVLW 0x90
MOVWF 0x23
MOVWF 0x24
CALL 0x50f
// -----------------------------
// Main loop
// -----------------------------
asm(&clrwdt&);
for (i=0; i&=MAXPOSX; i++)
INCF 0x22, F
MOVLW 0x11
SUBWF 0x22, W
BTFSS 0x3, 0
GOTO 0x7b8
ClearDisplay();
CALL 0x4eb
Printxy(i , 1, '*');
INCF 0x23, F
MOVLW 0x2a
MOVWF 0x24
MOVF 0x22, W
CALL 0x589
Printxy(MAXPOSX-i, 2, '*');
MOVWF 0x23
MOVLW 0x2a
MOVWF 0x24
MOVF 0x22, W
SUBLW 0x10
CALL 0x589
LongDelay(10);
MOVWF 0x23
CALL 0x50f
for (i=0; i&=MAXPOSX; i++)
INCF 0x22, F
ClearDisplay();
CALL 0x4eb
Printxy(MAXPOSX-i , 1, '*');
INCF 0x23, F
MOVLW 0x2a
MOVWF 0x24
MOVF 0x22, W
SUBLW 0x10
CALL 0x589
Printxy(i , 2, '*');
MOVWF 0x23
MOVLW 0x2a
MOVWF 0x24
MOVF 0x22, W
CALL 0x589
LongDelay(10);
1 members found this post helpful.
Full Member level 6
Re: LCD interfacing with a PIC - TUTORIAL -
Let me know if you need some help.
Junior Member level 2
Re: LCD interfacing with a PIC - TUTORIAL -
hi tekut...
i'm currently doing for the energy meter project...i'm using the pic16f877a...the input for this pic is current, voltage and also phase differnce cct...then the pic have to calculate the kwh and display it on the lcd...can u kindly provide the source code for me...
Full Member level 6
Re: LCD interfacing with a PIC - TUTORIAL -
Dear pisces12,
the source code is included into the tutorial and is written in C language for the Hi-Tech compiler.
1 members found this post helpful.
Newbie level 2
Re: LCD interfacing with a PIC - TUTORIAL -
hi tekut, i need help on keypad interfacing pic. what i have to do is almost like mobile keypad. As you imagine that, when i press the buttom of 2, it would show A, in 2 or 3 seconds, if i press it again, it would show on the lcd, B.. i got a code like this, but i'm not quite sure that it is true. So can you help me on that pls?? İ got 4x4 keypad, and pic 16F877A...
#define DELAY_FOR_NEXT 1000
// Delay before orginal Key is returnd time depends on how foten the &Call_Me_Every_1ms()& rutine is called
// Key_list[number of keys][number of characters/key]
// if you whant to have more characters on some keys then use a null on empty spots like below
//const unsigned char Key_list[9][6]={{'A','B','C','1',!,¤},{'D','E',0,0,'F','2',%,0},
{'G','H','I','3','&','&'},{'J','K','L','4',0,0},{'
M','N','O','5',0,0},{'P','Q','R','6',0,0},{'S','T'
,'U','7',0,0},{'V','W','X','8',0,0},{'Y','Z','9',' ',0,0}};
const unsigned char Key_list[9][4]={{'A','B','C','1'},{'D','E','F','2'},{'G','H','I'
,'3'},{'J','K','L','4'},{'M','N','O','5'},{'P','Q'
,'R','6'},{'S','T','U','7'},{'V','W','X','8'},{'Y'
,'Z','9',' '}};
unsigned short Delay_Timer= 0;
// Timer for delay
unsigned char NewKey= 0;
// use this as a way to see if the value is stepped or a new Key were pressed
void Call_Me_Every_1ms(){
// call this rutine at a steddy pase, if not value will step every time the DoKey() rutine is called whit the same value
if( Delay_Timer & 0xffff ) Delay_Timer++;
unsigned char DoKey(unsigned char Key) {
// call this rutine with the Key pressed &as a character 0-9& and it returnes the value to display if called whit any other it returns null
static unsigned char step,
if( Key & '0' || Key & '9' ) return 0;
// if not a valid value return null
if( Key == last && (Delay_Timer & DELAY_FOR_NEXT) ) { step++; NewKey= 1; } else { NewKey= 0; last= K step= 0; Delay_Timer= 0; }
// check if same Key and the amount of time is less then time before next Key should be displayd
if( (step &= sizeof(Key_list[0])) || (Key_list[Key-'0'][step] == 0 ) ) step= 0;
// if step is bigger than amount of chars in list or if null go to beginning of list
return Key_list[Key-'0'][step];
// return the value for the Key as a character
unsigned char tstkey= 0;
// only for test of this
unsigned char display_
// only for test of this
void main( void )
display_char= DoKey('1');
if( NewKey )
// this is a check if display should move to new position and desplay character, remove if not needed
Call_Me_Every_1ms();
// update timer
Delay_ms(1);
}while(1);
Newbie level 1
Re: LCD interfacing with a PIC16f877a
i m working on a project 'bite force measurement' for that i need to interface graphical lcd with pic16f877A using assembly language plz
post me the programm for the same.
Newbie level 6
Re: LCD interfacing with a PIC16f877a
Originally Posted by SAGAR(LEE)
i m working on a project 'bite force measurement' for that i need to interface graphical lcd with pic16f877A using assembly language plz
post me the programm for the same.
lcd asm code for
lcd C code for pic18F :
i hope it useful to u
Full Member level 5
Re: LCD interfacing with a PIC - TUTORIAL -
Below is some code I am working on, to create a LCD that can be connected to any device using a software serial protocol, if that is of any help. There is some delay routine that may not be used, but I just cut and paste these from other projects and saves reinventing the wheel.
list p=16f636
include &p16f636.inc&
0x21Delay counter
0x22Delay counter 2
0x23Delay counter 3
Start at the reset vector
code for bootloader
ORG 0x0000 ;reset vector
clrf 0x3 ;zero status
movlw 0x00 ;high byte of long jump &&&these next 2 lines are important
movwf 0xA ;zero PCLATH
goto start
;********************************************************************************************
;Setup up the delay routines that may be used
;delay of 1ms for 4mHz clock
delay_loop
delay_loop
;delay of 10ms for 4mHz clock
Delay_10ms
Delay_Loop_10ms
Delay_1 Call 1ms delay
Delay_Loop_10ms
;delay of 100ms for 4mHz clock
Delay_100ms
Delay_100x
Delay_Loop_100ms
Delay_1 Call 1ms delay
Delay_Loop_100ms
;delay of 1ms for 4mHz clock
Delay_Loop_1s
Delay_100 Call 100ms delay
Delay_Loop_1s
Delay_52ns
Delay_52ns_loop
Delay_52ns_loop
Delay_104ns
Delay_104ns_loop
Delay_104ns_loop
;********************************************************************************************
;initialize the display
delay2set up 20ms delay
delay_loop_10ms
delay2set up 5ms delay
delay_loop_10ms
set up 200us delay
delay_loop
set up 200us delay
delay_loop
delay2set up 5ms delay
delay_loop_10ms
;********************************************************************************************
delay_loop_10ms
delay_loop_10ms
;********************************************************************************************
set up 200us delay
delay_loop
set up 200us delay
delay_loop
;********************************************************************************************
;********************************************************************************************
intcon,RAIEenable interrupt on change
intcon,T0IEdisable TMR interrupt
;read our serial port baud
; wait for the serial port to go high
Wait_for_high
Wait_for_High
delay_52ns
Wait_for_High
;read the next 8 bits
delay_104ns
rec_byte,1
bit_count,1
delay_104ns
wait_for_high
wait_for_high
24th February 2011 at .
There are 10 kinds of people in the world.
Those who understand binary and those who don't.
Newbie level 1
Re: LCD interfacing with a PIC - TUTORIAL -
JUst learning about PIC16F877A using HI-TECH ANSI C Compiler.....
I just get this display on my LCD....
Junior Member level 3
Re: pic lcd tutorial
I am using PIC18F4220 and hi-tech compiler,but whenever i try to compile your source code .Following Errors occurs.
[141] C:\Documents and Settings\Administrator\My Documents\Downloads\lcddisp.c; 1.16 can't open include file &pic.h&: No such file or directory
I have also attached the pictures of the error i am facing
Please help me
I will be very thankful to you
Best Regards
Please login
, , , , , , , , ,}

我要回帖

更多关于 process id 1840 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信