יום חמישי, 14 במאי 2015

פונקציות נוספות למסך LCD.

תודה רבה לאלי בלש שכתב מספר פונקציות נוספות למסך LCD 2X18.
/*
moves to a given position on screen, 1 first, 32 last, use the following, lcd_moveto(3);
 */

void lcd_moveto(u8 loc) {
loc--; //to 0base
while (loc >= 32)
loc -= 32;
if (loc>=16) {
loc += 0x40 - 16;
}
lcd_write_add(loc);
}

//------------------------------------------------------------------------------------------------------
/*
prints any given number up to 2^32, usage: lcd_printn(1337);
 */

//reverses an array
void reverse(char *str, int len) {
int i=0, j=len-1, temp;
while (i<j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++; j--;
}
}

void lcd_printn(u32 n) {
int i = 0;
u8 str[10];
if (n==0) {
        lcd_write('0');
        return;
    }
while (n) {
str[i++] = (n%10) + '0';
n = n/10;
}
//reverse the array
reverse(str, i);
//print them.
lcd_printl(str,i);
}

אין תגובות:

הוסף רשומת תגובה