Драйвер для LCD TIC107(PCF2119x). Попробовал использовать индикатор Tic107. Написал к нему драйвер. Может быть будет полезен еще кому. Буду рад получить Ваши отзывы и замечания.
Драйвер:
//=================================================================================================
/*
Driver for the LCD TIC107(PCF2119x).
Interface i2c.
Compiler CCS.
Functions of the driver:
lcd_init() - initialization of the LCD,
lcd_putc(char c) - output of the symbol C (code ASCII 128-255) on current address DDRAM LCD,
lcd_putc_hex(char c) - output of the symbol C (code 0-255) on current address DDRAM LCD,
lcd_gotoxy(char x,char y) - set pointer of the DDRAM in position X of the string Y (1<=X<=16, 1<=Y<=16),
lcd_contrast(int8 val) - set contrast (0<=val<=63),
lcd_on_off(char p) - p=0 ===> LCD Off(power-down mode),p=1 ===> LCD On,
lcd_cursor(char c) - c=0 ===> cursor Off, c=1 ===> cursor On,
lcd_home() - reset pointer of the DDRAM,
lcd_blink(char b) - b=0 ===> character blink Off, b=1 ===> character blink On,
lcd_mirror(char m) - m='H' ===> mirror on horizontally,
- m='V' ===> mirror on vetically,
- m='R' ===> rotate horizontally and vertically by 180 degree,
- m='C' ===> cancel all the mirrors,
*/
//=================================================================================================
//----------Functions prototipes---------------------------
// ROM RAM
void lcd_init(); // 106 0
void lcd_putc(char c); // 75 2
void lcd_contrast(int8 val); // 64 2 // F1
void lcd_putc_hex(char c); // 63 1 // F2
void lcd_gotoxy(char x,char y); // 76 3 // F3
void lcd_on_off(char p); // 64 1 // F4
void lcd_cursor(char c); // 64 1 // F5
void lcd_home(); // 59 0 // F6
void lcd_blink(char b); // 64 1 // F7
void lcd_mirror(char m); // 88 1 // F8
//---------------------------------------------------------
//---------------------------------------------------------
/* Assign TRUE if function will used,
or FALSE if function will not used. */
#define F1 TRUE
#define F2 TRUE
#define F3 TRUE
#define F4 TRUE
#define F5 TRUE
#define F6 TRUE
#define F7 TRUE
#define F8 TRUE
//---------------------------------------------------------
#define rst PIN_C5 //the port of the microcontroller for reset LCD
#define address 0x74 //address of the TIC107 in i2c bus
//macros of the reset TIC107
#define reset_lcd_tic107 {output_high(rst);delay_ms(5);output_low(rst);delay_ms(5);}
//----------lcd_init(void)----------------------------------
void lcd_init(void)
{
reset_lcd_tic107;
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
i2c_write(0b00110100); // DL=1, M=1, SL=0, H=0
i2c_write(0b00001110); // D=1, C=1, B=0
i2c_write(0b00000110); // I/D=1, S=0
i2c_write(0b00110101); // DL=1, M=1, SL=0, H=1
i2c_write(0b00000011); // L=1
i2c_write(0b00000100); // P=0, Q=0
i2c_write(0b00001000); // IM=0, IB=0
i2c_write(0b00010000); // TC1=0, TC2=0
i2c_write(0b01000010); // S1=1, S0=0 (4x)
i2c_write(0b10000000 | 21); // V=0 (Val)
i2c_write(0b00110100); // DL=1, M=1, SL=0, H=0
i2c_stop();
}
//----------lcd_contrast(int8 val)-------------------------
#if F1
void lcd_contrast(int8 val)
{
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
i2c_write(0b00110101); // DL=1, M=1, SL=0, H=1
i2c_write(0b10000000 | val); // V=0 (Va)
i2c_write(0b00110100); // DL=1, M=1, SL=0, H=0
i2c_stop();
}
#endif
//----------lcd_putc(char c)-------------------------------
void lcd_putc(char c)
{
i2c_start();
i2c_write(address);
if (c=='\f')
{
i2c_write(0b00000000); // fuction set (Co=0, RS=0)
i2c_write(1); //clear display
}
else
{
if (c<10)
{
c+=0x30; //c is numeral
}
i2c_write(0b01000000); // write DATA (Co=0, RS=1)
i2c_write(c+0x80); //send char in the DDRAM
}
i2c_stop();
}
//----------lcd_putc_hex(char c)---------------------------
#if F2
void lcd_putc_hex(char c)
{
i2c_start();
i2c_write(address);
// if (c<10)
// {
// c+=0x30; //c is numeral
// }
i2c_write(0b01000000); // write DATA (Co=0, RS=1)
i2c_write(c); //send char in the DDRAM
i2c_stop();
}
#endif
//----------lcd_gotoxy(char x,char y)----------------------
#if F3
void lcd_gotoxy(char x,char y)
{
BYTE xy;
switch (y)
{
case 1 : xy=0x80;break; //0x80
case 2 : xy=0xc0;break; //0xc0
}
xy+=x-1;
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
i2c_write(0b00110100); // DL=1, M=1, SL=0, H=0
i2c_write(xy); //write Adress DDRAM
i2c_stop();
}
#endif
//----------lcd_on_off(char p)-----------------------------
#if F4
void lcd_on_off(char p)
{
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
if (p)
p=0b00001100; // display On, cursor Off, blink Off
else
p=0b00001000; // display Off, cursor Off, blink Off
i2c_write(p);
i2c_stop();
}
#endif
//----------lcd_cursor(char c)--------------------------------
#if F5
void lcd_cursor(char c)
{
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
if (c)
c=0b00001110; // display On, cursor On, blink Off
else
c=0b00001100; // display On, cursor Off, blink Off
i2c_write(c);
i2c_stop();
}
#endif
//----------lcd_home()-------------------------------------
#if F6
void lcd_home()
{
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
i2c_write(0b00110100); // DL=1, M=1, SL=0, H=0
i2c_write(0b00000010); // display home
i2c_stop();
}
#endif
//----------lcd_blink()---------------------------------
#if F7
void lcd_blink(char b)
{
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
if (b)
b=0b00001111; // display On, cursor On, blink On
else
b=0b00001100; // display On, cursor Off, blink Off
i2c_write(b);
i2c_stop();
}
#endif
//----------lcd_mirror(char m)---------------------------------
#if F8
void lcd_mirror(char m)
{
switch (m)
{
case 'H':
m=0b00000110;break; // mirror horizontaly (P=1, Q=0)
case 'V':
m=0b00000101;break; // mirror verticaly (P=0, Q=1)
case 'R':
m=0b00000111;break; // rotate by 180 degree (P=1, Q=1)
case 'C': default:
m=0b00000100;break; // cancel all the mirrors (P=0, Q=0)
}
i2c_start();
i2c_write(address);
i2c_write(0x00); // Co=0, RS=0
i2c_write(0b00110101); // DL=1, M=1, SL=0, H=1
i2c_write(m);
i2c_write(0b00110100); // DL=1, M=1, SL=0, H=0
i2c_stop();
}
#endif
//===============================================================================================
Демонстрационная программа:
----------main.h----------------
#include <16F886.h>
#device adc=8
#FUSES INTRC
#FUSES NOWDT //No Watch Dog Timer
#FUSES PUT //No Power Up Timer
#FUSES MCLR //Master Clear pin used for I/O
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES DEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
#use delay(clock=4000000)
#use i2c(Master,Fast,sda=PIN_C1,scl=PIN_C0)
-------main.c---------------
/*
Test of the tic107_driver.c.
Compiler CCS.
Microcontroller PIC16F886.
*/
#include "D:\KLG\PicProj\Proj_CCS\test_TIC107_driver\main.h"
#include "D:\KLG\PicProj\Proj_CCS\test_TIC107_driver\tic107_driver.c"
void main()
{
char tmp,i;
// Драйвер для
const byte str1[] = { 0x46,0xf0,0xe1,0x5a,0x6b,0xe5,0xf0,0xa0,
0x56,0x5b,0x7a,0xa0,0xa0,0xa0,0xa0,0xa0};
// COG 16x2 PCF2119
const byte str2[] = { 0xC3,0xCF,0xC7,0x20,0xB1,0xB6,0xF8,0xB2,
0x20,0xD0,0xC3,0xC6,0xB2,0xB1,0xB1,0xB9};
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);
lcd_init();
while (1)
{
lcd_putc('\f');
lcd_putc(5);
delay_ms(1000);
lcd_putc(0x45);
delay_ms(1000);
lcd_putc('A');
delay_ms(1000);
lcd_putc("A");
delay_ms(1000);
lcd_home();
lcd_mirror('H');
delay_ms(1000);
lcd_mirror('D');
delay_ms(1000);
lcd_mirror('V');
delay_ms(1000);
lcd_mirror('D');
delay_ms(1000);
lcd_mirror('R');
delay_ms(1000);
lcd_mirror('C');
lcd_home();
delay_ms(1000);
lcd_putc("Driver for the ");
lcd_gotoxy(1,2);
lcd_putc("Tic107 COG disp");
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
lcd_mirror('R');
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
lcd_on_off(0);
delay_ms(1000);
lcd_on_off(1);
delay_ms(1000);
lcd_blink(1);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
lcd_blink(0);
// output str1 in the first string
lcd_home();
lcd_mirror('C'); // cancel of the all mirrors
i2c_start();
i2c_write(address);
i2c_write(0b01000000); // Co=0, RS=1
for (tmp = 0; tmp < 16; tmp++)
lcd_putc_hex(str1[tmp]); //i2c_write(str1[tmp]);
i2c_stop();
// to second line
lcd_gotoxy(1,2);
// output str2 in the second string
i2c_start();
i2c_write(address);
i2c_write(0b01000000); // Co=0, RS=1
for (tmp = 0; tmp < 16; tmp++)
lcd_putc_hex(str2[tmp]); //i2c_write(str2[tmp]);
i2c_stop();
// mirrors
lcd_mirror('С');
delay_ms(2000);
lcd_mirror('H');
delay_ms(2000);
lcd_mirror('V');
delay_ms(2000);
lcd_mirror('R');
delay_ms(2000);
// change the contrast
for (tmp = 0; tmp < 64; tmp++)
{
delay_ms(100);
lcd_contrast(tmp);
}
lcd_mirror('C');
lcd_contrast(23);
//output all simbols
for(i=0;i<224;i+=32)
{
lcd_home();
for(tmp=0;tmp<16;tmp++)
{
lcd_putc_hex(i+tmp);
}
lcd_gotoxy(1,2);
for(tmp=16;tmp<32;tmp++)
{
lcd_putc_hex(i+tmp);
}
delay_ms(2000);
lcd_putc('\f');
lcd_home();
}
}
}
-
- Молодец, спасибо. Теперь реши проблему с регистрацией (напиши в Webmaster Zone) и добавь свой исходник в нашу коллекцию, т.к. пост быстро уплывет вниз --> - MBedder(17.03.2010 11:01, ссылка)
- Драйвер для LCD TIC107(PCF2119x). klgklg(51 знак., 17.03.2010 17:33, ссылка)
- лучше в исходники. - DL36(17.03.2010 18:05, ссылка)
- Именно сюда я и пытался поместить. klgklg(263 знак., 17.03.2010 18:23)
- Могу убрать пол-имени. - General(17.03.2010 18:04)
- Т.е. останется первоначальный ник klg? Буду благодарен. - klgklg(17.03.2010 18:12)
- лучше в исходники. - DL36(17.03.2010 18:05, ссылка)
- Драйвер для LCD TIC107(PCF2119x). klgklg(51 знак., 17.03.2010 17:33, ссылка)
- Молодец, спасибо. Теперь реши проблему с регистрацией (напиши в Webmaster Zone) и добавь свой исходник в нашу коллекцию, т.к. пост быстро уплывет вниз --> - MBedder(17.03.2010 11:01, ссылка)