Ну, разве что в качестве примера.
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Bill 27 декабря 2004 г. 08:59
В ответ на: Работа с LCD отправлено Валентин 27 декабря 2004 г. 07:54


#include "lcd.h"

//
// Static function prototypes
//
static void LCD_Write(unsigned char _ch);
static void LCD_WrNibl(unsigned char _ch);
static void LCD_CmdWr(unsigned char _ch);
static void LCD_Delay(void);

/* Global variable locations */

volatile char LCDCursor, // The current cursor position (0-15)
LCDLine; // The current line number (0-1)


//
// ** Delay100 -- the routine to do program delay of 0.1 mS
//
void Delay100(void)
{
SleepMCU(100);
}

//
// ** InitLCD -- routine to initialize LCD display
//
void InitLCD(void)
{
unsigned char _count = 20;

do // Power turn on delay
{
LCD_Delay();
}
while (--_count);
LCD_CmdWr(0x30);
LCD_CmdWr(LCD_Func); //Set to 4 bit interface
LCD_SendCmd(LCD_Func|TwoLin_BIT);// Set to 4 bit interface, 2 lines
// of 5x7 characters
LCD_SendCmd(LCD_OnOff); // Set Display Off
LCD_SendCmd(LCD_OnOff|Disp_BIT);// Set display On
Clear_LCD();
}

void Clear_LCD(void)
{
LCDCursor = LCDLine = 0; // Clear globals
LCD_SendCmd(LCD_Clear); //Clear display
LCD_Delay(); // Delay of 4.6 mS
LCD_SendCmd(LCD_Entry|INC_BIT); // Set cursor move to right
LCD_Home();
}

void LCD_Home(void) // Move cursor to the home position
{
LCD_MoveCurs(0);
}

void LCD_MoveCurs2(unsigned char _pos) // Move the display cursor
{
LCD_MoveCurs(_pos | LineNum_BIT); // Send the command to the LCD
}

void LCD_MoveCurs(unsigned char _pos) // Move the display cursor
{
LCD_SendCmd(_pos | LCD_DDRAM); // Send the command to the LCD
}
//
// ** LCD_SendCmd -- the routine sends a command to the LCD.
//
void LCD_SendCmd(unsigned char _ch)
{
LCD_CTRL &= ~LCD_RS; // Set LCD to command mode
LCD_Write(_ch);
}
//
// ** LCD_SendChr -- the routine sends a character to the LCD
//
void LCD_SendChr(unsigned char _ch)
{
LCD_CTRL |= LCD_RS; // Set LCD to data mode
LCD_Write(_ch); // Send the char
}
//
// ** LCD_Write -- the common routine to send command / data to the LCD
// It splits the character into the upper and lower
// nibbles and sends them to the LCD, upper nibble first
static void LCD_Write(unsigned char _ch)
{
LCD_WrNibl(_ch); // Send the upper nibble to the LCD first
LCD_WrNibl(_ch<<4); // and then the lower one
Delay100(); // Delay 100 uS
}

static void _delay(void)
{
_NOP();
_NOP();
_NOP();
_NOP();
}

static void LCD_WrNibl(unsigned char _ch) // The routine to write data nibble to the LCD
{
LCD_DATA = (_ch & DATA_MASK) | (LCD_DATA & ~DATA_MASK); // Output the upper nibble
_delay();
LCD_CTRL |= LCD_E; // Form LCD E pulse
_delay();
LCD_CTRL &= ~LCD_E; //
}

static void LCD_CmdWr(unsigned char _ch)
{ ;
LCD_WrNibl(_ch); // Write the command nibble
LCD_Delay();
}
//
// ** LCD_Delay -- the routine to do program delay of 4.6 mS approximately
//
static void LCD_Delay(void)
{
unsigned char _count = 46;

do
{
Delay100();
}
while (--_count);
}


Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru