Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lakin

Pages: [1]
1
Character LCDs / Re: NHD-0216K1Z
« on: July 21, 2017, 05:34:22 PM »
OK thanks.  I will be experimenting a little more and will use that method.  I'm a C programmer using a PIC.  Here is some C code if someone is interested.   To run it, header files, timers (delay) and variables need to be defined. 

void main(void) {
    TRISC = 0x00; //  this port is set for outputs
    TRISA3 = 0; //AN3 +VREF
    TRISA5 = 1; // AN4   bit 5 set as input
    ANSELH = 0x00;
    TRISB0 = 0; // enable signal output
    TRISB1 = 0; // read/write signal
    TRISB2 = 0; // register select signal   
   
    /******************************************/
    x = 0;  // debug breakpoint
    PORTC = 0x00;  // clear screen
    WriteCtl();  //  write commands
    delay(50);
    delta=500;
    cycle=40;
    //  continous run
    while(1){
      Init();
      DisplayInfo();
      delay(10000);
    }
 
}
 
void DisplayInfo(){   //disp_pic
  int i;
  Home();
    for (i=0;i<16;i++){   
       Write(text1);
        delay(1000);
        y = 0;  // debug breakpoint
    }
}
void Write(unsigned char Dat){
     
    PORTC = Dat;
    delay(5);
    RSHI; // RB2=1
    RWLO;//RB1=0; //write
    EHI; // RB0
    delay(100);
    ELO; //RB0
    RSLO;
    y=0;  // breakpoint
}

void Home(){
    PORTC = 0x02;  //home
    WriteCtl();
    delay(5);
    PORTC = 0x01;  // clear screen
    WriteCtl();
    delay(5);
}
void NextLine(){
    PORTC = 0xC0;
    WriteCtl();
}
// write controls

void WriteCtl(){   
    RSLO;
    RWLO; //RB1
    EHI; //RB0
    delay(10);
    ELO; //RB0
}

// AorD = 0 for address and 1 for data

void WriteAN(int AorD) {  // wrtAdr = 0; wrtNum = 1;
    RWLO;//RB1=0; //write
    ELO; // RB0
    if (AorD == 0) {
        RSLO; //RB2  address
    } else {
        RSHI; //RB2  data
    }
    delay(10);
    EHI;    //RB0=1;//EHI; //RB0
    delay(1);
    ELO; //RB0
}


void WriteInt(unsigned char initNum){
    PORTC = initNum;
    RSLO; // RB2
    RWLO;  // RB1
    EHI; // RB0
    delay(100);
    ELO; // RB0
    y=0; // breakpoint
}

void Init(){
 ELO;
 delay(500);    //Wait >40 msec after power is applied       
 WriteInt(0x30);  //command 0x30 = Wake up       
 delay(100);      //must wait 5ms, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #2       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #3       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x38);  //Function set: 8-bit/1-line       
 WriteInt(0x14);//Set cursor to right AC+1     
 WriteInt(0x0C);  //Display ON; Cursor ON       
 WriteInt(0x06);  //Entry mode set   cursor right DDRAM + 1
}
 



2
Character LCDs / Re: NHD-0216K1Z
« on: July 21, 2017, 10:13:37 AM »
Hi
Thank you for responding.  I got the unit working.
Notice :  Write(text1) did not have the i,  corrected Write(text1);

void DisplayInfo(){   //disp_pic
  int i;
  Home();
    for (i=0;i<8;i++){
        Write(text1); 
        y = 0;  // debug breakpoint
    }
}

3
Character LCDs / NHD-0216K1Z
« on: July 20, 2017, 09:05:58 AM »
I can display one letter, but debugging my program I'm sending more characters than aren't displayed.  Using PIC16F886.  I'm using code close to what I read on this forum.  I've enclosed the code, doing something wrong.
The initialization is copied from code on the forum.  Also I don't understand the newline command 0xC0 ?
The program will also be used later for AD converter.  But right now I want to get the display to work.  Plus it gives me some LCD display experience.

char const text1[] = {"Roger Lakin     " };
void main(void) {
    TRISC = 0x00; //  this port is set for outputs
    TRISB = 0xF8; //  all are set to inputs except the lower three
    TRISA3 = 0; //AN3 +VREF
    TRISA5 = 1; // AN4   bit 5 set as input
    TRISB0 = 0; // enable signal output
    TRISB1 = 0; // read/write signal
    TRISB2 = 0; // register select signal
    //ADCON0 = 0x11;  //  00 0100 0 1
    //ADCON1 = 0x80;  // ADFM = 1
    //ADRESH = 0x00;  // ADC 8 & 9 off
    //ADRESL = 0x10; //  ADC 4 turned on pin 7  RA5  ADC rest off
   
    /******************************************/
    x = 0;
//    Init();
    PORTC = 0x00;
    while(1){
        Init();
        DisplayInfo();
        delay(1000);
    }
 
}
 
void DisplayInfo(){   //disp_pic
  int i;
  Home();
    for (i=0;i<8;i++){
        Write(text1); 
        y = 0;  // debug breakpoint
    }
}
void Write(unsigned char Dat){
     PORTB = 0X00;
     PORTC = Dat;
     delay(10);
    RSLO; // RB2=0
    RWLO;//RB1=0; //write
    EHI; // RB0
    RSHI; //RB2  data
    delay(10);
    EHI;    //RB0=1;//EHI; //RB0
    delay(10);
    ELO; //RB0
    RSLO;
    //PORTC = 0x01;
    //WriteCtl();
    y=0;
}

void Home(){
    PORTC = 0x02;
    WriteCtl();
    delay(5);
}
void NextLine(){
    PORTC = 0xC0;
    WriteCtl();
}
// write controls

void WriteCtl(){
   
    RSLO;
    RWLO; //RB1
    EHI; //RB0
    delay(1);
    ELO; //RB0
    //RWHI; //RB1
    //RSHI; //RB2
   
}

// AorD = 0 for address and 1 for data

void WriteAN(int AorD) {  // wrtAdr = 0; wrtNum = 1;

    PORTB = 0X00;
    RWLO;//RB1=0; //write
    ELO; // RB0
    if (AorD == 0) {
        RSLO; //RB2  address
    } else {
        RSHI; //RB2  data
    }
    delay(1);
    EHI;    //RB0=1;//EHI; //RB0
    delay(1);
    ELO; //RB0
    //RB1=1;//RWHI; //RB1
    //RB2=1;//RSHI; //RB2
}


void WriteInt(unsigned char charNum){
    PORTC = charNum;
    RB2 = 0;//RSLO; // RB2
    RB1 = 0; // RWLO;  // RB1
    RB0 = 1; //EHI; // RB0
    delay(10);
    RB0 = 0; // ELO; // RB0
    y=0; // breakpoint
}

void Init(){
 ELO;
 delay(50);    //Wait >40 msec after power is applied       
 WriteInt(0x30);  //command 0x30 = Wake up       
 delay(100);      //must wait 5ms, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #2       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x30);  //command 0x30 = Wake up #3       
 delay(100);      //must wait 160us, busy flag not available       
 WriteInt(0x38);  //Function set: 8-bit/1-line       
 WriteInt(0x14);//Set cursor to rightAC+1     
 WriteInt(0x0C);  //Display ON; Cursor ON       
 WriteInt(0x02);  //Entry mode set   cursor right DDRAM + 1
}

Pages: [1]