2024. május 4., szombat

Gyorskeresés

KS0108 Kijelző meghajtó program PIC32-re(Csak 8pt magas karakterek)

Írta: |

[ ÚJ BEJEGYZÉS ]

Sok szenvedés után, eljutottam idáig: Működik (Es sejtem, hogy nem tökéletes ;] ) :K
Ez úton is szeretnek köszönetet mondani a C programozás topik lakóinak :R
A karakter lánc kiíratása specifikusan a szükségleteimhez lett tervezve azért olyan amilyen :DDD

Remélem valakinek jól fog jönni egyszer :K

Ez lenne a

screen.c

#include "font6x8_std.h"
#include "screen.h"
#include "membrane.h"

char compare[Display_pages]; //Store length of string for comparison
void InitalizePorts_display(void)
{
S_DATA_OUT=0;
S_DATA_IN=0;
DISPLAY_Dir=0;
DISPLAY_CS1=0;
DISPLAY_CS2=0;
DISPLAY_RS=0;
DISPLAY_RW=0;
DISPLAY_EN=0;

/* Command port direction settings */

DISPLAY_CS1_Direction =0 ;
DISPLAY_CS2_Direction =0 ;
DISPLAY_RS_Direction =0 ;
DISPLAY_RW_Direction =0 ;
DISPLAY_EN_Direction =0 ;

DelayUs(1000);
}

int lcd_select(int s)

{
if(s==0) //Selects the Left side of the screen
{

DISPLAY_CS1 = 1; //Selects Left side of the screen
DISPLAY_CS2 = 0; //Inhibit Right side of the screen
DelayUs(Hardware_delay);


}else if(s==1) //Selects the Right side of the screen
{

DISPLAY_CS1 = 0; //Inhibit Left side of the screen
DISPLAY_CS2 = 1; //Selects Right side of the screen
DelayUs(Hardware_delay);


}else if(s==2) //Select both sides of the screen
{

DISPLAY_CS1 = 1; //Selects Left side of the screen
DISPLAY_CS2 = 1; //Selects Right side of the screen
DelayUs(Hardware_delay);



}else{
return(1);
}
}

int strobe_E(void) //Turns enabling pages off/on
{

DISPLAY_EN = 1; //Turns Display On
DelayUs(Hardware_delay);
DISPLAY_EN = 0; //Turns Display Off
DelayUs(Hardware_delay);


}

int goto_xy(int x, int y) //Sets starting point on screen
{
DISPLAY_EN = 0; //Turns Display Off
DISPLAY_RS = 0; //Sets Instruction mode
if(y>=0 && y<(Display_width/2) && x<Display_pages && x>=0) //Checks if the data has to go to the left side
{
lcd_select(0);
S_DATA_OUT = (0b10111000+x); //Set X coordinate
strobe_E();
S_DATA_OUT = (0b01000000+y); //Set Y coordinate
strobe_E();

}else if(y>=(Display_width/2) && y<(Display_width) && x<Display_pages && x>=0){ //Checks if the data has to go to the right side
lcd_select(1);
S_DATA_OUT = (0b10111000+x); //Set X coordinate
strobe_E();
S_DATA_OUT = (0b01000000+(y-Display_width/2)); //Set Y coordinate included offset which is the half of the display size
strobe_E();
}else{
return(1);
}
}


int send_data_screen (long int Data) //Sends Data to the Display hardware
{
if(Data<=(Dislpay_height/Display_pages)*(Display_width/2) ) //Checks is the data length is valid
{
DISPLAY_EN = 0; //Turns Display Off
DISPLAY_RS = 1; //Enables Data mode
DelayUs(Hardware_delay);
S_DATA_OUT = Data; //Insert Data to the hardware line
strobe_E(); //Turns Display On/off
DISPLAY_RS = 0; //Disables Data mode

}else{
return(1);
}
}
int dsp_status(int status)
{
if(status=ON)
{
DISPLAY_RS = 0; //Instruction mode
DISPLAY_RW = 0; //Write Mode
DelayUs(Hardware_delay);
S_DATA_OUT = 0b00111111; //Turns display controller ON
strobe_E();
}else if(status=OFF)
{
DISPLAY_RS = 0; //Instruction mode
DISPLAY_RW = 0; //Write Mode
DelayUs(Hardware_delay);
S_DATA_OUT = 0b00111110; //Turns display controller OFF
strobe_E();
}else{
return(1);
}
}

int clr_page(int page_num)
{
if(page_num>=0 && page_num<Display_pages)
{ int y;
lcd_select(2); //Select both side of the display for quicker action
DISPLAY_RS = 0; //Sets Instruction mode
DISPLAY_RW = 0; //Write Mode
DelayUs(Hardware_delay);
S_DATA_OUT = (0b10111000+page_num); //Set Page address
strobe_E();
S_DATA_OUT = (0b01000000); //Set Y coordinate
strobe_E();
for(y=0; y<=(Display_width/2); y++) //Loop for the colum
{
send_data_screen(0x00); //Sends data to screen
}

}else{
return(1);
}
}

int clr_scr(void)

{
int x;

for(x=0; x<(Display_pages); x++) //Loop for the page selection
{
clr_page(x); //Delete the page selected by x
}

}
int write_char(int page_select, int y_offset, int charcater_code)

{ int x;
if(y_offset>=(Display_width/2) && y_offset<=Display_width-Font_width && charcater_code>=32 && charcater_code<=128) //Check which side of the screen need to be activated
{
goto_xy(page_select,y_offset);

for(x=(charcater_code-Font_offset)*Font_width; x<((charcater_code-Font_offset)*Font_width)+Font_width; x++) //Decodes the character code and make sure the data is sent by 8 bits
{
send_data_screen(Font[x]); //Sends out the relevant section of the Array
}
} else if(y_offset<(Display_width/2) && y_offset>=0 && charcater_code>=32 && charcater_code<=128)
{
goto_xy(page_select,y_offset); //Selects pages of writing
for(x=(charcater_code-Font_offset)*Font_width; x<((charcater_code-Font_offset)*Font_width)+Font_width; x++) //Decodes the character code and make sure the data is sent by 8 bits
{ if(y_offset+(x-(charcater_code-Font_offset)*Font_width)!=(Display_width/2)) //Checks if the character has reached the border of the 2 sides of the screen
{
send_data_screen(Font[x]);
}
else
{ //If the Character is belong to the right side
goto_xy(page_select,(Display_width/2)); //Selects pages of writing
send_data_screen(Font[x]); //Sends out the relevant section of the Array


}
}
}
else
{
MEMBRANE_MUTE=1;

}

}

int string_out(char* message, float variable,char Unit_of_measurment, int page, int y_offset, int Page_clear)
{
int Maximum_num_char= (Display_width-y_offset)/Font_width; //Maximum number of characters what can be placed in one page
char j;
char lenght_of_string;
char string[Maximum_num_char]; //Sets string array size to max_num_char in a page with the current offset
int size_of_variable=abs(variable); //Takes the integer part of the variable and applies ABS on it
if( size_of_variable>=0 && size_of_variable<10) //Checks the size_of_variable is in range
{
sprintf(string, "%s%.3f", message, variable+0.000499); //Sets number of char after decimal point to 3
}
else if( size_of_variable>=10 && size_of_variable<100) //Checks the size_of_variable is in range
{
sprintf(string, "%s%.2f", message, variable+0.00499); //Sets number of char after decimal point to 2
}
else if( size_of_variable>=100 && size_of_variable<1000) //Checks the size_of_variable is in range
{
sprintf(string, "%s%.1f", message, variable+0.0499); //Sets number of char after decimal point to 1
}
else if( size_of_variable>=1000 && size_of_variable<10000) //Checks the size_of_variable is in range
{
sprintf(string, "%s%.0f", message, (variable+0.499)); //Sets number of char after decimal point to 0
Page_clear=AUTO; //Sets Page_clear to AUTO mode to make sure the page will be cleared and no artifact remains
}
else //Else the size_of_variable is out of range
{
sprintf(string, "O/L",0,0); // Writes on screen O/L
}

lenght_of_string = strlen(string); //Returns with the length of the string which stored in "a" array

if(Page_clear==ON) //Always Clears the page before writes in it
{

clr_page(page);

}
else if(Page_clear==AUTO && lenght_of_string<compare[page]) //When the length of the string changes to be less than before, it clears the screen
{
clr_page(page);
compare[page]=lenght_of_string; //Writes the length of string into the comparison array compartment which is numbered by the page number
}
else if(Page_clear==OFF)
{

}else{
compare[page]=lenght_of_string; //Writes the length of string into the comparison array compartment which is numbered by the page number
}

write_char(page,y_offset+Font_width*lenght_of_string,Unit_of_measurment); //Writes unit of measurement after the string

for(j=0;j<lenght_of_string;j++)
{

write_char(page,y_offset+j*Font_width,string[j]); //Reads decoded characters from the string array and send it 1 by 1 to the screen

}
return(lenght_of_string);
}

Ez meg a screen.h

#ifndef screen_h /* Guard against multiple inclusion */
#define screen_h

#include "Hardware.h"
#define Display_width 128
#define Dislpay_height 64
#define Display_pages 8
#define Hardware_delay 2
#define UNIT_OF_RESISTANCE 127
#define UNIT_OF_VOLTAGE 86
#define UNIT_OF_CURRENT 65


//Screen Hardware Setup

#define DISPLAY_Dir TRISE
#define S_DATA_OUT LATE
#define S_DATA_IN PORTE
#define DISPLAY_CS1 LATGbits.LATG6
#define DISPLAY_CS2 LATDbits.LATD8
#define DISPLAY_RS LATGbits.LATG9
#define DISPLAY_RW LATDbits.LATD7
#define DISPLAY_EN LATDbits.LATD11
#define DISPLAY_CS1_Direction TRISGbits.TRISG6
#define DISPLAY_CS2_Direction TRISDbits.TRISD8
#define DISPLAY_RS_Direction TRISGbits.TRISG9
#define DISPLAY_RW_Direction TRISDbits.TRISD7
#define DISPLAY_EN_Direction TRISDbits.TRISD11

void InitalizePorts_display(void);
int lcd_select(int s);
int strobe_E(void);
int goto_xy(int x,int y);
int send_data_screen (long int Data);
int dsp_status(int status);
int clr_page(int page_num);
int clr_scr (void);
int write_char(int page_select, int y_offset, int charcater_code);
int string_out(char* message, float variable, char Unit_of_measurment, int page, int y_offset, int Page_clear);

#endif

Hozzászólások

(#1) DarthSun


DarthSun
nagyúr
LOGOUT blog

Kár hogy nem tudok C- ben programozni, a Pascal- t tanultam meg, az kellett a munkámhoz, aztán a kedvencemmé is vált.

(#2) #90088192 válasza DarthSun (#1) üzenetére


#90088192
törölt tag

Én sem tudok C. ben programozni, csak tanulgatok, és szintén zenész, ált iskola ahol Pascalt tanított a matek tanár. :DDD

(#3) DarthSun válasza #90088192 (#2) üzenetére


DarthSun
nagyúr
LOGOUT blog

Jó, hát az iskolai tanítás-tanulás...én még hosszú ideig tanultam Oroszt, aztán xarra sem emlékszem. A Pascal már az első melóhelyemen. Sokcsatornás analizátor, többdimenziós tömbök, mátrixok, differenciál, integrál. Az utóbbi kettőt a suliban nemnagyon értettem :B , aztán a munkában kénytelen voltam felfogni. A sok agyi izzadás után meg annyira megkedveltem a Pascalt, hogy otthon is hobbi szinten programoztam. Saját SB meghajtó, hangerőszabályzó, segédprogramok, stb. Már nem programozok, de végülis ha valaki alaposan megtanulja, olyan mint a biciklizés, nemlehet elfelejteni.

[ Szerkesztve ]

(#4) #90088192 válasza DarthSun (#3) üzenetére


#90088192
törölt tag

:R

Ahogy latod, nekem ez nem kenyerem, csak hobbi, így nagyot sem alkottam, sőt inkább a semmihez konvergál :DDD

Az azért nem egyszerű, SB driver, ahogy emlékszem egy sima COM port megnyitása is ASM-ben történt(mint kb az összes program nyelvben kivéve ASM ;] )

(#5) DarthSun válasza #90088192 (#4) üzenetére


DarthSun
nagyúr
LOGOUT blog

Az ASM rutinokkal egyszerű dolgom volt, megkaptam a teljes regiszterkészlet elérési listáját. Csak eljárásokba kellett illesztenem, azokat pedig TPU- ba. Aztán egy rezidens váz Pascalban, főrutin inittel, a rezidensbe meg lehet berántogatni az ASM procedurákat. Ja persze még a memben maradó hosszát kell pontosan kiszámolni, aztán kész is.

(#6) #90088192 válasza DarthSun (#5) üzenetére


#90088192
törölt tag

Van meg mit tanulnom :K

Most éppen bővíteném a tudását a meghajtó programnak, persze valamiért csak nem megy :O
Ahogy a Pascal mondaná: Type mismatch error
Csak nem jövök rá miért :N

Sebaj, vannak nálam sokkal okosabbak :K

(#7) DarthSun válasza #90088192 (#6) üzenetére


DarthSun
nagyúr
LOGOUT blog

Nem is az okosságon múlik egy közép-haladó szint elérése, inkább az idő,gyakorlás. Azt szoktam mondani hogy átlagos IQ- val, kinyitva egy tankönyvet az alapokig jutni 1 év, aztán a haladó olyan 5-6 év még, persze folyamatos gyakorlással. Persze a 180- as IQ- val rendelkező egyik haveromnak töredék idő kellett. A tényekből már sokat felejtettem, de az visszakereshető, az elméleti rutin marad meg inkább.

További hozzászólások megtekintése...
Copyright © 2000-2024 PROHARDVER Informatikai Kft.