PicGIM example - EVENTS and TIMER

 

 Resources Version  Download Size  Date
 HT002_PG_LCD_HD44780_HelloWorld  0.1 256KB   10/05/2015

 

RELATED TO THIS EXAMPLE :

DELAY module

HD44780 module

PINS name

DEFINES

This howto is part of the kit PicGIM 0.5 library.


This howto is part of the kit PicGIM 0.5 library.

In this example we analyze how to configure PicGIM and how to write the right code

with the purpose of writing a text on a HD44780 controller 16x2 lcd display, using the busy flag bit.

The aim is to write "Hello world!" on the first line, starting from the third column.

We choose to use, for example, a PIC18F4620 with a 40MHz oscillator.

As always, the first thing to do is to configure the file "pgim_project_setup_public.h" to customize the project.

In this example we filled out the necessary fields in this way:

 

 

 

//P R O J E C T   D E T A I L S

#define PG_PROJECT_NAMELCD_HD44780_HelloWorld

#define PG_PROJECT_ORGANIZATIONgKript Howto

#define PG_PROJECT_AUTHORskymatrix

#define PG_PROJECT_VERSION0.1

#define PG_PROJECT_STATEPG_DEBUG

#define PG_PROJECT_DATE07/05/2015

 

//H A R D W A R E   C O N F I G   M A I N   S Y S T E M

#define PG_CLOCK40.000

#define PG_USER_SUPPLY_VOLT5.00

#define PG_USER_SUPPLY_BATTERYPG_NO

#define PG_USE_INTERNAL_OSCPG_DISABLE

 

//P I C G I M   B E H A V I O U R

#define PG_VERBOSEPG_ENABLE

#define PG_SUGGESTIONPG_ENABLE

#define PG_PROJECT_INFO_SHOWPG_ENABLE

 

Before compile PicGIM we still have to set some configuration files.

The "pgim_module_setup_public.h" file defines which modules are included and compiled.

This example code requires the presence of the LCD_HD44780 module.

The LCD module is dependent on the DELAY module, then this one must also be enabled.

If you do not enable it, PicGIM will return a compilation error.

 

The DELAY module is software and is part of the SOFTWARE GENERAL category.

This means that I do not have to assign any pins to the devices.

The DELAY module not needs to be configured, it is crucial to indicate correctly

the oscillator frequency, so that it can correctly calculate timings.

 

Here, there are the necessary settings:

 

//S O F T W A R E   G E N E R A L

#define PGIM_ERRORPG_DISABLE

#define PGIM_CAL_DELAYPG_ENABLE

#define PGIM_FTOAPG_DISABLE

 

//H A R D W A R E   I N T E R N A L

#define PGIM_EVENTSPG_DISABLE

#define PGIM_AD_CONVERTERPG_DISABLE

#define PGIM_SPIPG_DISABLE

#define PGIM_EEPG_DISABLE

#define PGIM_TIMERPG_DISABLE

#define PGIM_PWMPG_DISABLE

#define PGIM_SERIALPG_DISABLE

 

//H A R D W A R E   E X T E R N A L

#define PGIM_LCD_HD44780PG_ENABLE

#define PGIM_BUZZERPG_DISABLE

#define PGIM_SENSORPG_DISABLE

 

//H A R D W A R E   G K R I P T

#define PGIM_ENCODERPG_DISABLE

 

Always in the same "pgim_module_setup_public.h" file, if required,

we must modify the related software configuration.

In a 2x16 lcd display there is only one on-board controller.

Controllers not used must be declared unused, by PG_MISSING define.

We need to read busy flag bit, from lcd.

The first line is at address 0x00.

We want a spash screen for a time of two seconds.

Here, there are the necessary settings:

 

#definePG_LCD_HD44780_COLUMNS16

#definePG_LCD_HD44780_LINES2

#define PG_LCD_HD44780_BUSY_FLAGPG_ENABLE

#define PG_LCD_HD44780_LINE_0_ADDRESS0x00

#define PG_LCD_HD44780_LINE_1_ADDRESSPG_MISSING

#define PG_LCD_HD44780_LINE_2_ADDRESSPG_MISSING

#define PG_LCD_HD44780_LINE_3_ADDRESSPG_MISSING

#define PG_LCD_HD44780_SPLASH_ENABLEPG_ENABLE

#define PG_LCD_HD44780_SPLASH_TIME2

 

 

Now that the modules are enabled and software side configured, we must configure the HARDWARE.

LCD_HD44780 is an external devices and is part of the category HARDWARE EXTERNAL;

this means that Pic pins are to be assigned to display, in order to be able to control its functions.

These settings are made by editing the dedicated section in the file "pgim_hardware_setup_public.h".

Our display has a single controller, then only one enable pin.

It is provided of a led backlight (BL), so a pin is dedicated to drive it.

We will use it in the configuration with four bits of data.

We assign the following pin as in the following table:

 

Lcd RS pin -> Pic LATD, bit 4

Lcd RW pin -> Pic LATD, bit 5

Lcd EN pin -> Pic LATD, bit 6

 

Lcd D0 pin -> Pic LATD, bit 0

Lcd D1 pin -> Pic LATD, bit 1

Lcd D2 pin -> Pic LATD, bit 2

Lcd D3 pin -> Pic LATD, bit 3

 

Lcd BL pin -> Pic LATD, bit 7

 

We must also specify, when required, if some pins are being used or not.

If not, we have to indicate them are missing by PG_MISSING define

(referring to the relative physical pin define) and by PG_NO (referring

to the related "_PRESENT" define).

After the latch bits, in the same way, we assign the right tris bits

and also the right port bits (because we have to read the busy flag bit ).

It is of fundamental importance that the number of the port pins

is the same for all three values!

Here, there are the required settings:

 

#define PG_LCD_HD44780_RSL_D4

#define PG_LCD_HD44780_RW_PRESENTPG_YES

#define PG_LCD_HD44780_RWL_D5

#define PG_LCD_HD44780_EN_0_PRESENTPG_YES

#define PG_LCD_HD44780_EN_0L_D6

#define PG_LCD_HD44780_EN_1_PRESENTPG_NO

#define PG_LCD_HD44780_EN_1PG_MISSING

#define PG_LCD_HD44780_EN_2_PRESENTPG_NO

#define PG_LCD_HD44780_EN_2PG_MISSING

#define PG_LCD_HD44780_EN_3_PRESENTPG_NO

#define PG_LCD_HD44780_EN_3PG_MISSING

#define PG_LCD_HD44780_DATA_0L_D0

#define PG_LCD_HD44780_DATA_1L_D1

#define PG_LCD_HD44780_DATA_2L_D2

#define PG_LCD_HD44780_DATA_3L_D3

#define PG_LCD_HD44780_BL_PRESENTPG_YES

#define PG_LCD_HD44780_BLL_D7

 

#define PG_LCD_HD44780_RS_TRIST_D4

#define PG_LCD_HD44780_RW_TRIST_D5

#define PG_LCD_HD44780_EN_0_TRIST_D6

#define PG_LCD_HD44780_EN_1_TRISPG_MISSING

#define PG_LCD_HD44780_EN_2_TRISPG_MISSING

#define PG_LCD_HD44780_EN_3_TRISPG_MISSING

#define PG_LCD_HD44780_DATA_0_TRIST_D0

#define PG_LCD_HD44780_DATA_1_TRIST_D1

#define PG_LCD_HD44780_DATA_2_TRIST_D2

#define PG_LCD_HD44780_DATA_3_TRIST_D3

#define PG_LCD_HD44780_BL_TRIST_D7

 

#define PG_LCD_HD44780_DATA_0_PORTP_D0

#define PG_LCD_HD44780_DATA_1_PORTP_D1

#define PG_LCD_HD44780_DATA_2_PORTP_D2

#define PG_LCD_HD44780_DATA_3_PORTP_D3

 

It is also possible not to use the busy flag. Of course it will lose speed, but we save a pin

because the RW must remain fixed at low level (the display will only be written and never read).

Now, here we have the only defines that need to be changed in the configuration just created to not use the busy flag bit:

 

Lcd RW pin -> not used (permanently connect it to low level)

#define PG_LCD_HD44780_BUSY_FLAGPG_DISABLE

#define PG_LCD_HD44780_RW_PRESENTPG_NO

#define PG_LCD_HD44780_RWPG_MISSING

#define PG_LCD_HD44780_RW_TRISPG_MISSING

#define PG_LCD_HD44780_DATA_0_PORTPG_MISSING

#define PG_LCD_HD44780_DATA_1_PORTPG_MISSING

#define PG_LCD_HD44780_DATA_2_PORTPG_MISSING

#define PG_LCD_HD44780_DATA_3_PORTPG_MISSING

 

If the backlight is not present, files must be configured in this way:

 

#define PG_LCD_HD44780_BL_PRESENTPG_NO

#define PG_LCD_HD44780_BLPG_MISSING

#define PG_LCD_HD44780_BL_TRISPG_MISSING

 

Now PicGIM is properly configured for the project to be developed.

These are the warnings that PicGIM returns during compilation.

If all goes well they will be like these :

 

Warning [2105] PicGIM:  Core >  Version "0.5-0"  : Milestone "0.5"  : State "rel" 

Warning [2105] PicGIM:  Message >  ~~~  Check periodically on www.gkript.org if you are using the latest PicGIM released!

Warning [2105] -

Warning [2105] -

Warning [2105] PicGIM:  Project: [ LCD_HD44780_HelloWorld   V 0.1  ] by [ gKript Howto  ]  -  Author: [ skymatrix/asyntote  ]

Warning [2105] -

Warning [2105] -

Warning [2105] PicGIM:  Core >  Set 18F4620 as current mcu

Warning [2105] PicGIM:  Core >  Using EXTERNAL oscillator ( 40.000  [MHz] )

Warning [2105] PicGIM:  Core >  ~~~  All fuses are set as you want.

Warning [2105] PicGIM:  Core >  ~~~  TRADITIONAL code activated but EXTENDED Instructions Set is available with this MCU. Keep on mind!

Warning [2105] PicGIM:  Core >  Set MCU POWER SUPPLY to 5.00  [V]

Warning [2105] PicGIM:  Core >  Make sure that the 5.00  voltage is enough for the clock frequency chosen.

Warning [2105] PicGIM:  DELAY module >  Loaded

Warning [2105] PicGIM:  Note >  INTERRUPTS disabled

Warning [2105] PicGIM:  Note >  ~~~  Keep in mind that PicGim offers a very simple way to use them. See the documentation.

Warning [2105] PicGIM:  LCD HD44780 module >  Loaded

 

 

At this point you can compile the project and verify that the display power on backlight, shows the slpash screen and then correctly print the string on the first line from the third column.