?? lcd_v1.2.c
字號(hào):
/*=============================================================================
// File : LCD_V1.1.c //
// //
// Abstract: The source file containing the required control and disp fun //
// Compiler : IAR Embedded Work Bench //
// //
// Author : Kuberappa.M.Sajjan //
// E-mail : kuber@unifiest.com //
// //
// //
=============================================================================*/
/*---------------------------- Preprocessor Directives ----------------------*/
#include "io430.h"
#include "datatypes_v1.1.h"
#include "lcd_v1.1.h"
/*--------------------------- Macros and Constants --------------------------*/
#define LCD_DELAY_1 {UINT lcd_delay; for(lcd_delay = 0;\
lcd_delay<9600;lcd_delay++);}
#define LCD_DELAY_2 {UINT lcd_delay; for(lcd_delay = 0;\
lcd_delay<7500;lcd_delay++);}
#define LCD_DATA_DELAY {UCHAR lcd_data_del;for(lcd_data_del = 0;\
lcd_data_del<0x75;lcd_data_del++);}
/*-------------------------- Global Variable Declarations -------------------*/
/*-------------------------- Function Prototypes ----------------------------*/
/*=============================================================================
= FUNCTION_NAME: =
= port_initialisation() =
= =
= Design Description: This function Initialises the GPIO =
= Inut Parameters : None =
= Return Type: =
= =
=============================================================================*/
void port_initialisation(void)
{
LCD_DATA_DIR = OUT_BIT; // Set the O/P Direction for LCD Data bit
LCD_CLK_DIR = OUT_BIT; // Set the O/P Direction for LCD clock bit
RS_DIR = OUT_BIT; // Set the O/P Direction for LCD RS bit
EN_DIR = OUT_BIT; // set the O/P Direction for LCD EN bit
}
/*=============================================================================
= FUNCTION_NAME: =
= lcd_initialisation() =
= =
= Design Description: This function Initialises the LCD Display =
= Inut Parameters : None =
= Return Type: =
= =
=============================================================================*/
void lcd_initialisation(void)
{
port_initialisation(); // Initialise the Port Direction for LCD
lcd_data(FUNCTION_SET,CLR); // Send the Function Set Command
LCD_DELAY_1; // Wait for some delay
lcd_data(CLEAR_DISPLAY,CLR); // Clear Display
LCD_DELAY_1; // Wait for some delay
lcd_data(CURSOR_ON,CLR); // Cursor On
LCD_DELAY_1; // Wait for some delay
lcd_data(ENTRY_MODE,CLR); // Address on the LCD
}
/*=============================================================================
= FUNCTION_NAME: =
= lcd_data() =
= =
= Design Description: This function writes the data and control byte on =
= the display =
= Inut Parameters : UCHAR,UCHAR =
= Return Type: =
= =
=============================================================================*/
void lcd_data(UCHAR write_byte,UCHAR cmd)
{
if(SET == cmd) // if the par cmd is 1
{
RS = SET; // set the RS bit for data display on the LCD
}
else if(CLR == cmd) // if the par cmd is 0
{
RS = CLR; // clr the RS bit for write the contr on the
// LCD
}
convert_data(write_byte); // Convert byte into bits
EN = SET; // Set the En signal
LCD_DATA_DELAY; // wait for some transition
EN = CLR; // Send Low pulse to Enable the Latch
}
/*=============================================================================
= FUNCTION_NAME: =
= convert_data() =
= =
= Design Description: This function sends the data interms of bits. =
= Input Parameters : UCHAR =
= Return Type: =
= =
=============================================================================*/
void convert_data(UCHAR convdata)
{
UCHAR convert = 0;
UCHAR rol = 0;
while(rol<EIGHT) // Send the Eight Bit
{
LCD_CLK_BIT = CLR; // Send Intially low Clk
if((convdata&0x80)== 0) // Its check the MSB bit is One or
{ // Zero
LCD_DATA_BIT = CLR; // If Zero, sends the Zero to Shift
}
else
{
LCD_DATA_BIT = SET; // Other Wise sends One
}
LCD_CLK_BIT = SET; // Sends the Clock as high
convdata = convdata<<1; // Shift the data for once left
rol++; // Increment the count for
}
}
/*=============================================================================
= FUNCTION_NAME: =
= lcd_displaydata() =
= =
= Design Description: This function sends the string of data to LCD =
= Input Parameters : UCHAR, UCHAR, UCHAR =
= Return Type: =
= =
=============================================================================*/
void lcd_displaydata(UCHAR row ,UCHAR col, const UCHAR *str)
{
lcd_cursor(row,col); // Position the cursor at required position
while('\0'!= *str) // Check for the end bytes
{
lcd_data(*str,SET); // Display the Character
str++; // Increment the Pointer
}
}
/*=============================================================================
= FUNCTION_NAME: =
= lcd_cursor() =
= =
= Design Description: This function puts the position for LCD to Disp =
= Input Parameters : UCHAR, UCHAR =
= Return Type: =
= =
=============================================================================*/
void lcd_cursor(UCHAR row, UCHAR col) // It position the Cursor to req position
{
switch(row) // check the row value
{
case 1: lcd_data(0x80 + col-1,CLR); // If row one put cursor to req col
break;
case 2: lcd_data(0xC0 + col-1,CLR); // If row one put cursor to req col
break;
default:
break;
}
}
/*=============================================================================
= FUNCTION_NAME: =
= lcd_displayfloat =
= =
= Design Description: This function displays the float value on Display =
= Input Parameters : UCHAR, UCHAR, FLOAT =
= Return Type: =
= =
=============================================================================*/
/*void lcd_displayfloat(UCHAR row, UCHAR col,FLOAT data)
{
ULONG data_l,val;
UCHAR disp_val = 0;
float fltval;
fltval = data;
lcd_cursor(row,col);
// The modification is on 12.12.08 From Kuber
// Displaying the voltage on the display with five precisions
// Displaying the First higher byte
data_l = data*100000;
val = data_l/100000;
disp_val = val;
disp_val = disp_val + ASCII;
lcd_writedata(disp_val);
// Displaying the second higher byte after decimal point
data_l = data_l - val*100000;
val = data_l/10000;
disp_val = val;
disp_val = disp_val + ASCII;
lcd_writedata(disp_val);
// Displaying the third higher byte
data_l = data_l - val*10000;
val = data_l/1000;
disp_val = val;
disp_val = disp_val + ASCII;
lcd_writedata(disp_val);
// Displaying the fourth higher byte
data_l = data_l- val*1000;
val = data_l/100;
disp_val = val;
disp_val = val+ASCII;
lcd_writedata(disp_val);
lcd_writedata('.');
// Displaying the Fifth higher byte
data_l = data_l - val*100;
val = data_l/10;
disp_val = val;
disp_val = val +ASCII;
lcd_writedata(disp_val);
// Displaying the Lowest byte
disp_val = val%10;
disp_val = disp_val + ASCII;
lcd_writedata(disp_val);
}*/
/*=============================================================================
= FUNCTION_NAME: =
= lcd_displayfloat =
= =
= Design Description: This function displays the wt on the Display =
= Input Parameters : UCHAR, UCHAR, FLOAT =
= Return Type: =
= =
=============================================================================*/
void lcd_display_float_wt(UCHAR row,UCHAR col, FLOAT Float)
{
UINT Int_disp; // Declare the Variable for internal use
lcd_cursor(row,col); // Position the cursor at required position
Int_disp = Float*10; // Convert the Float value into integer
send_float_disp(Int_disp,100); // Send the Higher nibble for display
Int_disp = Int_disp%100; // Get the reminder from the integer value
send_float_disp(Int_disp,10); // send the Second higher nibble for display
lcd_data('.',SET); // Put the decimal point after two valuews
Int_disp = (Int_disp%10); // Get the lower nibble
send_float_disp(Int_disp,1); // Display on the display
}
void send_float_disp(UINT int_disp, UCHAR div)
{
int_disp = int_disp/div; // Convert the byte into nibble
lcd_data((int_disp + ASCII),SET);// Display the value on the Display
}
/* The modification in this file is Grounding the RW signal on LCD Display always
Also giving the 5 digit precision on the LCD */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -