Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

16*4 LCD Ekran Sorunu

Başlatan elektroacemi, 06 Ocak 2022, 11:35:40

elektroacemi

Alıntı yapılan: yas - 06 Ocak 2022, 17:14:02Tamam onu da sen düzelt :)  sonuçta deneyerek yapmıyorum mantığını anlatmaya çalıştım.  ::ok

Çok teşekkür ederim :)


serkan

xc8 de böyle yapılıyor.

#define      LCD_CLEAR              1
#define      LCD_CURSOR_OFF          12
#define      LCD_TURN_OFF            0
#define      LCD_TURN_ON            8
//////////////////////LCD  PORT AYATLARI///////////////////////////////////////////////////////////////////////////////////////
#define LCD_data7      PORTDbits.RD7      // D7
#define LCD_data6      PORTDbits.RD6      // D6
#define LCD_data5      PORTDbits.RD5      // D5
#define LCD_data4      PORTDbits.RD4      // D4
#define LCD_EN        PORTCbits.RC7      // EN
#define LCD_RS        PORTCbits.RC6      // RS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Lcd_Init(void);
void Lcd_yazi(unsigned char y, unsigned char x, const char *buffer);
void Lcd_Char(char c);
void Lcd_komut(unsigned char c);
void print(unsigned char y, unsigned char x, char *buffer); 
void ozel_karekter(char location, unsigned  char *ptr);
 void karekter_oku(unsigned char y, unsigned char x, char *buffer);
void MCU_Delayms(unsigned int time);  
int i;
float sayi;
unsigned char Temp[50];
char pil_seviye[8]={14,17,17,31,31,31,31,0}; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//==============================================================================
void Lcd_komut(unsigned char c){
LCD_EN = 0; LCD_RS = 0;
LCD_data7 = (c & 0x80)>>7; 
LCD_data6 = (c & 0x40)>>6;
LCD_data5 = (c & 0x20)>>5; 
LCD_data4 = (c & 0x10)>>4;
LCD_EN = 1;__delay_ms(2); LCD_EN = 0; __delay_ms(9);  
LCD_data7 = (c & 0x08)>>3; 
LCD_data6 = (c & 0x04)>>2;
LCD_data5 = (c & 0x02)>>1; 
LCD_data4 = (c & 0x01);
LCD_EN = 1;__delay_ms(2); LCD_EN = 0;__delay_ms(9);  

}

void Lcd_Init(void){
unsigned char data; __delay_ms(2);
LCD_data7 = 0;LCD_data6 = 0;LCD_data5 = 0;LCD_data4 = 0;  
LCD_EN = 0;LCD_RS = 0;__delay_ms(2); 
for(data = 1; data < 4; data ++){
LCD_data7 = 0;LCD_data6 = 0;LCD_data5 = 1;LCD_data4 = 1;
LCD_EN = 0;LCD_RS = 0; __delay_ms(2); 
LCD_data7 = 0;LCD_data6 = 0;LCD_data5 = 1;LCD_data4 = 1;  
LCD_EN = 1;LCD_RS = 0;__delay_ms(2);  
LCD_data7 = 0;LCD_data6 = 0;LCD_data5 = 1;LCD_data4 = 1;  
LCD_EN = 0;LCD_RS = 0;__delay_ms(2); 
}
LCD_data7 = 0;LCD_data6 = 0;LCD_data5 = 1;LCD_data4 = 0; 
LCD_EN = 0;LCD_RS = 0; __delay_ms(2);  
LCD_data7 = 0;LCD_data6 = 0;LCD_data5 = 1;LCD_data4 = 0;  
LCD_EN = 1;LCD_RS = 0;__delay_ms(2);  
LCD_data7 = 0;LCD_data6 = 0;LCD_data5 = 1;LCD_data4 = 0; 
LCD_EN = 0;LCD_RS = 0;__delay_ms(9); 
data = 40; Lcd_komut(data);
data = 16; Lcd_komut(data);
data = 1;  Lcd_komut(data);
data = 15; Lcd_komut(data);__delay_ms(2); 
Lcd_komut(LCD_CURSOR_OFF);
} 

//==============================================================================
void Lcd_Char(char c){
LCD_EN = 0; LCD_RS = 1;__delay_us(30); 
LCD_data7 = (c & 0x80)>>7; 
LCD_data6 = (c & 0x40)>>6;
LCD_data5 = (c & 0x20)>>5;
LCD_data4 = (c & 0x10)>>4;
__delay_us(30);
LCD_EN = 1;__delay_us(30);LCD_EN = 0; __delay_us(30); 
LCD_data7 = (c & 0x08)>>3;
LCD_data6 = (c & 0x04)>>2;
LCD_data5 = (c & 0x02)>>1; 
LCD_data4 = (c & 0x01);
__delay_us(30); 
LCD_EN = 1;__delay_us(30);LCD_EN = 0; __delay_ms(9); 
}
 
void print(unsigned char y, unsigned char x, char *buffer){
unsigned char data;
switch(y){
case 1: data = 127 + x; break;  
case 2: data = 191 + x; break;
case 3: data = 147 + x; break;
case 4: data = 211 + x; break;
default: break;}
Lcd_komut(data);
while(*buffer)              
    {
      Lcd_Char(*buffer);
      buffer++;            
    }
return;
}
 void karekter_oku(unsigned char y, unsigned char x, char *buffer){
unsigned char data;
switch(y){
case 1: data = 127 + x; break;  
case 2: data = 191 + x; break;
case 3: data = 147 + x; break;
case 4: data = 211 + x; break;
default: break;}
Lcd_komut(data);
Lcd_Char(*buffer);
}
void Lcd_yazi(unsigned char y, unsigned char x, const char *buffer){
unsigned char data;
switch(y){
case 1: data = 127 + x; break;
case 2: data = 191 + x; break;
case 3: data = 147 + x; break;
case 4: data = 211 + x; break;
default: break;}
Lcd_komut(data);
while(*buffer)            
    {
      Lcd_Char(*buffer);
      buffer++;          
    }
return;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MCU_Delayms(unsigned int time){
    unsigned int acc;
    for(acc=0; acc<time; acc++){
        __delay_ms(1);
    }
}

void ozel_karekter(char location, unsigned  char *ptr)
{
 char i;
 unsigned  char *lkb;
  lkb=ptr;

    Lcd_komut(64+(location*8));
           for(i=0;i<8;i++)
               Lcd_Char(lkb[i]);
 
}

 
void  main( )  {

INTCON2bits.RBPU =0; //B portu direncleri aktif
CMCON = 0b00000111;  //karsilastirici iptal
TRISA=0x07;TRISB=0xFF;TRISC = 0x00;TRISD=0x00;  TRISE = 0x00;  
PORTA=0x00;PORTB=0x00; PORTC=0x00; PORTD=0x00;PORTE=0x00;  
MCU_Delayms(250);
Lcd_Init();  
MCU_Delayms(1000);//0.5 saniye
sayi=15.026;
 sprintf(Temp,"%0.2f",sayi);
 print(1,1, &Temp[0]);
MCU_Delayms(1000);//0.5 saniye
i=1000; 
 sprintf(Temp,"%4d",i);
 print(2,1, &Temp[0]);
MCU_Delayms(500);//1 saniye

Lcd_yazi(3,1,"789");MCU_Delayms(500);//0.5 saniye
Lcd_yazi(4,1,"aBc");MCU_Delayms(500);//0.5 saniye

ozel_karekter(0,pil_seviye);//karekteri 0 adresine kaydet
karekter_oku(1,10,0);//karekteri 0  adresineden oku 1. satir 10 nuncu sutuna yaz.

while(1) {       
 sayi+=0.1; MCU_Delayms(250);
 
 sprintf(Temp,"%0.2f",sayi);
 print(2,10, &Temp[0]);
  

      } 
  } 





Maxim

:020000040000FA
:1000000000000000A2EF00F01200016A018E0A6EEB
:10001000FE0E53D80A5051D0A66AA68E0900F5509C
:1000200002E002D8FBD71200086E8B90899C949056
:10003000929CF00E9516085000B21ED03A0E046E37
:10004000980E4BD8330E076E29D8130E046E880E07
:1000500044D824D8640E40D821D8640E3DD8220E4E
:10006000076E1CD8280E07D80C0E05D8060E03D82C
:100070000082085001D00080076E00A009D0899C42
:1000800003080AE309D8070E046ED00E26D8120022
:100090000080FE0810E0898C073A00A000908B8059
:1000A000F00E831607500F0B83128B90073A00B0A7
:1000B000F5D7320E11D80850120001BEB5D7066A26
:1000C000056EFF0E0526062200D0D8A01200030EF2
:1000D000046EE30E02D8F5D7046AF50F036EFE0E28
:1000E00004E300D000000326FDE20000032604061E
:1000F000F9E203A002D000D000001200616161614A
:10010000616161616161616161616161000062629F
:100110006262626262626262626262626262000083
:10012000636363636363636363636363636363639F
:100130000000646464646464646464646464646447
:1001400064640000006A00010F0EC16E070EB46EF9
:10015000700ED36E929C9490938C938A938893861E
:100160009384928A9380969496929690929E929877
:10017000948A948C806A896A816A8A6A826A8B6AA4
:10018000836A8C6A846A8D6AF19E070EB46EF28E61
:1001900003D0F2BE120055D0FCDFFBDFF00EF26E92
:1001A000F8DFF7DF840ED56EF4DFF3DFF294F1DFD2
:1001B000F0DF0F0ED66EEDDFECDFF19CEADFE9DF5A
:1001C000F292E7DF030E066EE80E7ADFE2DF05EE5D
:1001D000FFF0ED6AE950EA10FCE1EF6ADADF030EA6
:1001E000066EE80E6DDFD5DFFE0E1EDF010E1CDF92
:1001F000D0DF800E016E09DF000EF76EFC0EF66E8A
:100200000BDFC7DF800E016EC00EFFDE010EF76E42
:100210000E0EF66E01DFBDDF800E016E940EF5DE70
:10022000010EF76E200EF66EF7DEB3DF800E016E64
:10023000D40EEBDE010EF76E320EF66EEDDEA9DFA8
:10024000CDD7F29EF2A403D0F2940F0ED66EF2B286
:0E025000F292F28E11009DDFFED79BDFFED7EB
:020000040030CA
:0300010008011ED5
:02000500018177
:0600080000800FE00F4034
:00000001FF