Понимаю что смешно, но помогите пожалуйста куском кода или последовательностью его написания.
Как его, чтобы проинициализировать и просто замигал курсор в первой позиции.
16х2, 4-х битный интерфейс, Си.
Технический форум по робототехнике.
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN = 1),(LCD_EN = 0),(LCD_EN = 0)) //extra-wide strobe pulse
//DataImage LCD pins - CHANGE THAT IF LCD PINOUT DIFFERS !!!
#define bit7 lcd4 //Register select (0=command, 1=data)
#define bit6 lcd5 //R/W (0=write, 1=read)
#define bit5 lcd6 //Enable (active high strobe)
#define bit4 lcd7
#define bit3 lcd8
#define bit2 lcd9
#define bit1 lcd10
#define bit0 lcd11
#define LCD_RS lcd14
#define LCD_RW lcd13
#define LCD_EN lcd12
// DO NOT CHANGE - IT"S SCHEMATICS!!!!
#define lcd4 RB0 //Register select (0=command, 1=data)
#define lcd5 RA6 //R/W (0=write, 1=read)
#define lcd6 RA7 //Enable (active high strobe)
#define lcd7 RA3
#define lcd8 RA0
#define lcd9 RA2
#define lcd10 RA1
#define lcd11 RB7
#define lcd12 RB6
#define lcd13 RB5
#define lcd14 RB4
void lcd_init(void) {
LCD_RS = 0; //write control bytes
LCD_RW = 0; //write mode
delayMs(200); //power on delay. LCD spec is 15 but some don't make it
// PORTB = 0x30; //4 bit mode init 1st
bit4 = 1;
bit5 = 1;
LCD_STROBE;
delayMs(20);
LCD_STROBE; //4 bit mode init 2nd
delayMs(20);
LCD_STROBE; //4 bit mode init 3rd
delayMs(20);
/* PORTB = 0x20; //set 4 bit mode
LCD_STROBE;
delayMs(5);*/
lcd_putcmd(0x38); //4 bit mode, 1/16 duty, 5x7 font
// lcd_putcmd(0x3C); //4 bit mode, 1/16 duty, 5x10 font
lcd_putcmd(0x08); //display off
lcd_putcmd(0x0C); //display on, no cursor
lcd_putcmd(0x06); //entry mode = increment cursor, freeze display (no shift)
} //END OF lcd_init()
void lcd_putcmd(byte cmd) {
// byte scratch;
LCD_RS = 0; //instruction mode
LCD_RW = 0; //write mode
LCD_putbyte(cmd);
/*scratch = cmd; //mask out RB0 (GPO1)
PORTB = scratch; //upper nibble
LCD_STROBE;
scratch = (cmd << 4); //mask out RB0 (GPO1)
PORTB = scratch; //lower nibble */
LCD_STROBE;
//lcd_waitbusy();
if (cmd <= 3) //using instead of waitbusy - my LCD doesn't reliably drive busy line???
{
delayMs(2); //instructions 1-3 take about 1.5ms
}
delay100us(); //other instructions take about 40ms
}
void Init (void);
void Strob (void)
{
PORTD.f6 = 1; //E
PORTD.f6 = 1; //E
asm nop;
PORTD.f6 = 0; //E
PORTD.f6 = 0; //E
asm nop;
}
void main()
{
Init(); // èíèöèàëèçèðóåì ïîðòû
PORTD.f5 = 0; //RS
Delay_ms(200);
PORTE.f0 = 0; // DB7
PORTE.f1 = 0; // DB6
PORTE.f2 = 1; // DB5
PORTD.f7 = 0; // DB4
Strob();
Delay_ms(50);
Strob();
Delay_ms(50);
Strob();
Delay_ms(50);
//---
PORTE.f0 = 0; // DB7
PORTE.f1 = 0; // DB6
PORTE.f2 = 1; // DB5
PORTD.f7 = 1; // DB4
Delay_us(100);
Strob();
PORTE.f0 = 1; // DB7
PORTE.f1 = 0; // DB6
PORTE.f2 = 0; // DB5
PORTD.f7 = 0; // DB4
Delay_us(100);
Strob();
Delay_ms(20);
PORTE.f0 = 0; // DB7
PORTE.f1 = 0; // DB6
PORTE.f2 = 0; // DB5
PORTD.f7 = 0; // DB4
Delay_us(100);
Strob();
PORTE.f0 = 1; // DB7
PORTE.f1 = 0; // DB6
PORTE.f2 = 0; // DB5
PORTD.f7 = 0; // DB4
Delay_us(100);
Strob();
Delay_ms(20);
PORTE.f0 = 0; // DB7
PORTE.f1 = 0; // DB6
PORTE.f2 = 0; // DB5
PORTD.f7 = 0; // DB4
Delay_us(100);
Strob();
PORTE.f0 = 1; // DB7
PORTE.f1 = 1; // DB6
PORTE.f2 = 0; // DB5
PORTD.f7 = 0; // DB4
Delay_us(100);
Strob();
Delay_ms(20);
PORTE.f0 = 0; // DB7
PORTE.f1 = 0; // DB6
PORTE.f2 = 0; // DB5
PORTD.f7 = 0; // DB4
Delay_us(100);
Strob();
PORTE.f0 = 0; // DB7
PORTE.f1 = 1; // DB6
PORTE.f2 = 1; // DB5
PORTD.f7 = 0; // DB4
Delay_us(100);
Strob();
Delay_ms(20);
PORTD.f5 = 1; //RS
PORTE.f0 = 1; // DB7
PORTE.f1 = 1; // DB6
PORTE.f2 = 1; // DB5
PORTD.f7 = 1; // DB4
Delay_us(100);
Strob();
PORTE.f0 = 1; // DB7
PORTE.f1 = 1; // DB6
PORTE.f2 = 1; // DB5
PORTD.f7 = 1; // DB4
Delay_us(100);
Strob();
Delay_ms(20);
//------------------------------
for(;;)
{
}
}
void Init (void)
{
ADCON0 = 0b00000001;
ADCON1 = 0b00000001;
ADCON2 = 0b00001001;
CMCON = 0b00000111; //disabled
INTCON = 0b10000000;
//GIE, PEIE, TMR0IE, INT0IE, RBIE, TMR0IF, INT0IF, RBIF
INTCON2 = 0b11000000;
INTCON3 = 0b00000000;
T0CON = 0b01000100;
/*
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD6_bit;
sbit LCD_D4 at RD7_bit;
sbit LCD_D5 at RE2_bit;
sbit LCD_D6 at RE1_bit;
sbit LCD_D7 at RE0_bit;
*/
TRISA = 0;
PORTA = 0;
TRISB = 0;
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISC.f0 = 1;
TRISD = 0;
PORTD = 0;
TRISE = 0;
PORTE = 0;
}
dccharacter писал(а):А как выглядит символ 0xff?