0% found this document useful (0 votes)
17 views24 pages

Lecture 6 Mikro C PIC Libraries

Uploaded by

Craig Peri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views24 pages

Lecture 6 Mikro C PIC Libraries

Uploaded by

Craig Peri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Mikro C PIC Libraries

1
Library Functions
• Mikro C provides libraries for use when working with
on board PIC modules and external PIC-compatible
hardware devices.

• A library contains functions that are used with a


particular module or piece of hardware.

• It reduces programming work during development

• To illustrate using the LCD library

2
LCDs
• An LCD uses crystals that block light when current
passes through them.

• The crystals are built into pixels that can each be


uniquely controlled to block or let through the light.
• The assembly is placed in front of a light source.

• Current is selectively passed through the pixels


• Pixels carrying current block light and form dark spots
thus generating display patterns

3
LCDs

14 segment LCD 7 segment LCD


display unit
4
LCDs

Character LCDs Graphic LCDs


5
Character LCD
• It is used to display characters (ASCII and related).
• Each character is displayed on a 5x7 pixel or a 5x8 matrix.

6
Character LCD
• It is used to display characters (ASCII and related).
• Each character is displayed on a 5x7 pixel or a 5x8 matrix.

7
Character LCD
• Display size described as number of characters per line
and the number of lines, for example 16x2 LCD.

8
Character LCD
• A character on a character LCD is identified by a line
number and its position in the line.

Character at row 1,
column 7

Character at row 3,
column 9
9
Interfacing to Character LCD
• LCD displays have large number of control signals and
lines to control the large number of pixels involved.
• They are thus constructed as modules containing the
display and an interface IC.

• Interface IC used to handle control of the pixels.


• Microcontroller then interfaces using a few external lines

• Logically, LCD display seen as two registers.


• Command register for sending instructions to display.
• Data register for exchange of data with display.
10
Interfacing to Character LCD

Power supply LED power


pins
Contrast
pins 11
Interfacing to Character LCD

Enable
line

Data lines
Register
Read/write
select line 12
Select line
Interfacing to Character LCD
• Interface to a microcontroller can be 8-bit interface or
4-bit interface.

• In 8-bit mode, all the data pins DB0 to DB7 form an 8-


bit data bus.
• Characters are exchanged in one cycle.

• In 4-bit mode, data pin DB4 to DB7 form the data bus
while DB0 to DB3 are left free.
• The rest of the pins retain their functions.
• Characters are exchanged in two cycles.
13
Interfacing to Character LCD
4-bit
interface
wiring for
writes only

14
LCD Library

• The Mikro C LCD Library supports 4-bit interface using


lines RS, EN and DB4 – DB7.

• R/W line is kept low (i.e. writes only).

15
LCD Library
• LCD library routines use global variables of the
external sfr bit type to identify pins and
corresponding TRIS bits.

Variables used for pins: Variables used for TRIS bits:


 LCD_RS  LCD_RS_Direction
 LCD_EN  LCD_EN_Direction
 LCD_D7  LCD_D7_Direction
 LCD_D6  LCD_D6_Direction
 LCD_D5  LCD_D5_Direction
 LCD_D4  LCD_D4_Direction
16
LCD Library
• The variables need to be defined before the library
routines can be used using the at keyword.
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit; 17
LCD Library
void Lcd_Init()
• initializes LCD

void Lcd_Out(char row, char column, char *text)


• Prints text on Lcd starting from specified position.
• row: starting position row number
• column: starting position column number
• text: text to be written

18
LCD Library
void Lcd_Out_Cp(char *text)
• Prints text on Lcd at current cursor position.
• text: text to be written

void Lcd_Chr(char row, char column, char out_char)


• Prints character on Lcd at specified position.
• row: writing position row number
• column: writing position column number
• char: character to be written

19
LCD Library
void Lcd_Chr_Cp(char out_char)
• Prints character on Lcd at current cursor position.
• out_char: character to be written

void Lcd_Cmd(char out_char)


• Sends command to Lcd.
• out_char: command to be sent

20
LCD Library
void Lcd_Chr_Cp(char out_char)
• Prints character on Lcd at current cursor position.
• out_char: character to be written

void Lcd_Cmd(char out_char)


• Sends command to Lcd.
• out_char: command to be sent
• Library has predefined constants to represent the
various commands
21
Lcd Command Purpose
_LCD_FIRST_ROW
_LCD_SECOND_ROW
LCD Library
Move cursor to the 1st row
Move cursor to the 2nd row
_LCD_THIRD_ROW Move cursor to the 3rd row
_LCD_FOURTH_ROW Move cursor to the 4th row
_LCD_CLEAR Clear display
_LCD_RETURN_HOME Return cursor to home position
_LCD_CURSOR_OFF Turn off cursor
_LCD_UNDERLINE_ON Underline cursor on
_LCD_BLINK_CURSOR_ON Blink cursor on
_LCD_MOVE_CURSOR_LEFT Move cursor to left
_LCD_MOVE_CURSOR_RIGHT Move cursor to right
_LCD_TURN_ON Turn Lcd display on
_LCD_TURN_OFF Turn Lcd display off
_LCD_SHIFT_LEFT Shift display left
_LCD_SHIFT_RIGHT Shift display right 22
Using LCD Libraries
• Tick LCD library in the library manager.

• Define the variables to be used as per the connections


between the LCD and the PIC ports.

• Initialize the LCD using Lcd_Init() [in main()]

• Proceed to perform desired operations by running


library functions as necessary.

• Steps are also applicable to other libraries


23
Laboratory 5
Control of a Matrix keypad and an LCD

•Design Circuit and enter on Proteus


•Develop Program and enter on Mikro C
•Simulate the system
•Build actual circuit
•Download into a PIC and test

24

You might also like