Hirdetés

Új hozzászólás Aktív témák

  • #90088192

    törölt tag

    Hello Mindenkinek :)

    Igen kezdő vagyok minden szinten, ezert nagyon alap kérdésem, lenne amit nehéz megfogalmazni, számomra, így nem is egyszerű megtalálni a szagirodalomban.

    MPLAB-ban készítettem egy működő kódot ami egy kijelzőt vezérel, eddig jó, van két .h fajlom az egyik a hardware deklaráció, a másik maga a font.
    Maga a source file screen.c neven futott és tartalmazott egy void main bejegyzést, amit alá írtam az lefutott.

    Amit csinálni szeretnek, létrehozni egy main.c nevű fájlt, és abba meghívni a screen.c ben összedobott szubrutinokat. Ezt így megpróbáltam, és többszörös definícióra hivatkozik folyamatosan.
    Valaki el tudna mondani mit csinálok rosszul? :R

    Maga a main.c

    #include <stdlib.h>
    #include "screen.c"

    /*
    *
    */
    int main()
    {

    unsigned int x;

    InitalizePorts_display();

    //Wait for Vcc to settle
    delay(100);
    // Turn on display
    dsp_on();
    lcd_select(2);
    clr_scr(0x00);


    //*************************************************************************
    // Test
    //*************************************************************************


    for(x=0;x<2000;x++)
    {
    float a=(73.00/5);


    string_out("Spotty:", x ,1,0);
    delay(10000);

    }


    return (EXIT_SUCCESS);
    }

    es ez lenne a kijelző vezérlő

    #include "hardware.h"
    #include "font6x8.h"



    void delay(unsigned int usec)
    {
    _delay_us(usec);
    }

    void lcd_select(int s)
    {
    if(s==0)
    {
    DISPLAY_CS1 = 1; //Selects Left side of the screen
    DISPLAY_CS2 = 0; //Deselects Right side of the screen
    delay(10);
    }else if(s==1)
    {
    DISPLAY_CS1 = 0; //Deselects Left side of the screen
    DISPLAY_CS2 = 1; //Selects Right side of the screen
    delay(10);
    }else{
    DISPLAY_CS1 = 1; //Selects Left side of the screen
    DISPLAY_CS2 = 1; //Selects Right side of the screen
    delay(10);
    }
    }

    void strobe_E(void) //Turns enabling line off/on
    {
    DISPLAY_EN = 0;
    delay(10);
    DISPLAY_EN = 1;
    delay(10);
    }

    void set_y(int y) //Set Y coordinate 0-63 on the active side of the screen
    {
    //Y address
    DISPLAY_RS = 0;
    S_DATA_OUT = (0b01000000+y);
    strobe_E();
    }


    void dsp_on(void)
    {
    DISPLAY_RS = 0; //Instruction mode
    S_DATA_OUT = 0b00111111; //Turns display on
    //DISPLAY_RS = 1; //Data Mode
    delay(10);
    strobe_E();
    }

    void clr_scr (int t)
    {
    int x; int y;
    //line_0();
    DISPLAY_RS = 0;
    S_DATA_OUT = 0b11111111;
    for(y=0b10111111;y>=0b10111000;y--)
    {
    set_y(0);
    DISPLAY_RS = 0;
    S_DATA_OUT = y;
    strobe_E();
    for(x=0; x<64; x++)
    {
    dsp_on();
    DISPLAY_EN = 1;
    DISPLAY_RS = 1;
    S_DATA_OUT = t;
    strobe_E();
    };
    };


    }

    void write_char(int line_select, int y_offset, int c)

    { int x; int t;
    if(y_offset>63 && y_offset<122) //Check which side of the screen need to be activated
    {lcd_select(1); //if the offset is bigger than 63 than the right side

    t=(y_offset-64); //correction of the offset for the right side
    set_y(t);

    DISPLAY_RS = 0;
    S_DATA_OUT = 0b10111000+line_select; //select line
    strobe_E();

    for(x=(c-32)*6; x<((c-32)*6)+6; x++) //Decodes the character code and make sure the data is sent by 8 bits
    {
    DISPLAY_RS = 1;
    S_DATA_OUT = font6x8[x];
    strobe_E();
    }
    }else if(y_offset<64 && y_offset>=0)
    {

    lcd_select(0); //selects the left side of the screen

    t=(y_offset);
    set_y(t);

    DISPLAY_RS = 0;
    delay(10);
    S_DATA_OUT = 0b10111000+line_select;
    strobe_E();

    for(x=(c-32)*6; x<((c-32)*6)+6; x++) //Decodes the character code and make sure the data is sent by 8 bits
    {if(t+(x-(c-32)*6)==63) //checks if the character has reached the border of the 2 sides of the screen
    {lcd_select(1); //If yes selects the the right side
    delay(10);
    DISPLAY_RS = 0;
    S_DATA_OUT = 0b10111000+line_select; // Select the relevant line
    strobe_E();
    set_y(0); // Resets the offset
    delay(2);
    DISPLAY_RS = 1;
    S_DATA_OUT = font6x8[x]; //send out the data what belongs to the right side of the screen
    strobe_E();
    }else{ //If the Character is belong to the left side
    DISPLAY_RS = 1;
    S_DATA_OUT = font6x8[x]; //Sends the data to the screen
    strobe_E();
    }
    }
    }
    else
    {
    lcd_select(2);
    clr_scr(0xff);
    }

    }

    void string_out(char* message, float variable, char line, char y_offset)
    {
    char test[21],i=0,j;
    char a[21];
    sprintf(a, "%s%f", message, variable);
    while(a[i]!='\0') {test[i]=a[i]; i++;}
    for(j=0;j<=i-1;j++) write_char(line,y_offset+j*6,test[j]);

    }

Új hozzászólás Aktív témák