攪左差唔多 2 星期既 KS0108 LCD
#yeah# 幾時可以將塊 Bread Board 轉成 PCB ? #photo# 已經轉左了!#ham_sub#第一張一排黃線果塊已經係…有埋 IC,今朝影的…
面包板係 2-13 係 lab 影… 廢機影廢相… o甘係時候簡化 o的線 & 寫個 user friendly 的 program 出來了 #yeah# #eh#我而家玩緊bs2 [quote]原帖由 [i]觀星是答案[/i] 於 2007-2-24 10:52 發表
o甘係時候簡化 o的線 & 寫個 user friendly 的 program 出來了 #yeah# [/quote]應該唔會了…
就係 program 佢出個溫度同時間已經寫左 1 星期…#bye#
佢係 graphical lcd,入面冇文字的!
因此要好似 php 咁 load ttf 檔用 gd 將文字變成 wbmp 圖,然後再寫多個 program load 個 wbmp 黎 show 圖! 仲咩唔用你部 dslr 影 ??? 塊LCD係邊度買架? 幾$? 華輝 $300 [quote]原帖由 [i]閒魂[/i] 於 25/2/2007 01:14 發表
華輝 $300 [/quote]#eh#同我地粒bs2差唔多 [quote]原帖由 [i]Enzo[/i] 於 2007-2-25 01:42 發表
#eh#同我地粒bs2差唔多 [/quote]bs2 係咩黎? [quote]原帖由 [i]閒魂[/i] 於 2007-2-25 03:53 發表
bs2 係咩黎? [/quote]
basic stamp 2 [quote]原帖由 [i]閒魂[/i] 於 2007-2-24 23:21 發表
應該唔會了…
就係 program 佢出個溫度同時間已經寫左 1 星期…#bye#
佢係 graphical lcd,入面冇文字的!
因此要好似 php 咁 load ttf 檔用 gd 將文字變成 wbmp 圖,然後再寫多個 program load 個 wbmp 黎 show 圖! ... [/quote]
不如share....
等其他有心人同你改 #drool# [quote]原帖由 [i]nissin[/i] 於 2007-2-26 08:18 發表
不如share....
等其他有心人同你改 #drool# [/quote]
呢個係將 192x64 的 wbmp 經 stdin 輸入,再 display 到 lcd 的程式…
[code]#include <stdio.h>
#include <stdlib.h>
#include "serdisplib/serdisp.h"
int main(int argc, char **argv) {
char sdcdev[] = "0x378";/* use parallel port */
char dispname[] = "KS0108";/* display name */
serdisp_CONN_t* sdcd;
serdisp_t* dd = 0;
int i,j,x,y;
unsigned char b;
sdcd = SDCONN_open(sdcdev);
dd = serdisp_init(sdcd, dispname, "width=192;delay=400;invert=yes");
//serdisp_clear(dd);
x=0;y=0;
getchar();getchar();getchar();getchar();getchar();
for (j=0;j<64;j++) {
for (i=0;i<24;i++) {
b = getchar();
if (b >= 128) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=128;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
if (b >= 64 ) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=64;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
if (b >= 32 ) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=32;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
if (b >= 16 ) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=16;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
if (b >= 8 ) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=8;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
if (b >= 4 ) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=4;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
if (b >= 2 ) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=2;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
if (b >= 1 ) {serdisp_setpixel(dd, x, y, SD_COL_BLACK); b-=1;}
else serdisp_setpixel(dd, x, y, SD_COL_WHITE); x++;
} x=0; y++;
}
serdisp_setpixel(dd, 191,63,SD_COL_BLACK); // This statement is used to prevent some bugs of libserdisp.
serdisp_update(dd);
return(0);
}[/code] 用 gd 將文字轉 wbmp
[code]#include "gd.h"
#include <string.h>
#include <stdio.h>
#include <getopt.h>
char *utf2ucs(char *outs, const unsigned char *c);
int main(int argc, char *argv[]) {
gdImagePtr im;
int black;
int white;
int brect[8];
int x, y;
char *err;
FILE *out;
int option;
char *s = "Default string ä½| æ²~Ræ~\~I輸å~E¥ä»»ä½~Uå~W串";
double sz = 8.;
char *z = " ";
char *f = "/usr/share/fonts/fireflysung/fireflysung.ttf";
while ((option = getopt(argc, argv, "s:f:z:")) != EOF) {
switch (option) {
case 's' : s = strdup(optarg) ; break;
case 'f' : f = strdup(optarg) ; break;
case 'z' : z = strdup(optarg) ; break;
}
}
sz = atoi(z);
if (sz == 0) sz = 8.;
/* content of brect[8]
6,7 4,5
+---------------+
| |
| |
+---------------+
0,1 2,3 */
im = gdImageCreate(192,64);
white = 0; //gdImageColorResolve(im, 255, 255, 255);
black = 1; //gdImageColorResolve(im, 0, 0, 0);
x = 0; // - brect[6];
y = sz+1; // - brect[7];
/* char *gdImageStringFT (
gdImagePtr im,
int *brect,
int fg,
char *fontname,
double ptsize,
double angle,
int x, int y,
char *string ) */
err = gdImageStringFT(im,&brect[0],black,f,sz,0.0,x,y,s);
if (err) {fprintf(stderr,err); return 1;}
gdImageWBMP(im, white, stdout); // fclose(out);
gdImageDestroy(im);
}
char *utf2ucs(char *outs, const unsigned char *c) {
int x, x1, x2, x3;
int i;
for (i=0;i<strlen(c);i++) {
if (c[i] < 128)
sprintf(outs, "%s%c",outs, c[i]);
else if (c[i] >= 192 && c[i] < 224) {
x1 = c[i] - 192;
x2 = c[i+1] - 64;
i++;
x = x1 * 128 + x2;
sprintf(outs, "%s&#%d;",outs, x);
} else if (c[i] >= 224 && c[i] < 240) {
x1 = c[i] - 224;
i++;
x2 = c[i] - 128;
i++;
x3 = c[i] - 128;
x = x1 * 4096 + x2 * 64 + x3;
sprintf(outs, "%s&#%d;",outs, x);
} else printf("Unxpected character\n");
}
return outs;
}
[/code] 有無for Parallel 行 HD44780 的 program#drool#
#include "gd.h"
#include "serdisplib/serdisp.h" <---- 呢2個去邊度搵? sereach libgd 同 libserdisp 就會有!
hd44780 簡單得多!#ham_sub#
lcd.h
[code]//#include <dos.h>
#include <string.h>
//#include <conio.h>
#include <time.h>
#include <stdio.h>
#include <asm/io.h>
#include <unistd.h>
#define PORTADDRESS 0x378 /* Enter Your Port Address Here */
#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2
void lcd_init(void);
void lcd_write(char char2write);
void lcd_putch(char char2write);
void lcd_puts(char * str2write);
void lcd_goto(int row, int column);
void lcd_clear(void);
void lcd_home(void);
void lcd_cursor(int cursor);
void lcd_entry_mode(int mode);
[/code]
lcd.c
[code]#include "lcd.h"
void lcd_init()
{
// outb(CONTROL, inb(CONTROL) & 0xDF);
outb(inb(CONTROL) & 0xDF, CONTROL);
//config data pins as output
// outb(CONTROL, inb(CONTROL) | 0x08);
outb(inb(CONTROL) | 0x08, CONTROL);
//RS is made high: control (register select)
lcd_write(0x0f);
usleep(20000);
lcd_write( 0x01);
usleep(20000);
lcd_write( 0x38);
usleep(20000);
}
void lcd_write(char char2write)
{
outb(char2write,DATA);
outb(inb(CONTROL) | 0x01 ,CONTROL); /* Set Strobe */
usleep(200);
outb(inb(CONTROL) & 0xFE, CONTROL); /* Reset Strobe */
usleep(200);
}
void lcd_putch(char char2write)
{
outb(inb(CONTROL) & 0xF7, CONTROL);
//RS=low: data
lcd_write(char2write);
}
void lcd_puts(char *str2write)
{
outb(inb(CONTROL) & 0xF7, CONTROL);
//RS=low: data
while(*str2write)
lcd_write(*(str2write++));
}
void lcd_goto(int row, int column)
{
outb(inb(CONTROL) | 0x08, CONTROL);
if(row==2) column+=0x40;
/* Add these if you are using LCD module with 4 columns
if(row==2) column+=0x14;
if(row==3) column+=0x54;
*/
lcd_write(0x80 | column);
}
void lcd_clear()
{
outb(inb(CONTROL) | 0x08, CONTROL);
lcd_write(0x01);
}
void lcd_home()
{
outb(inb(CONTROL) | 0x08, CONTROL);
lcd_write(0x02);
}
void lcd_entry_mode(int mode)
{
/*
if you dont call this function, entry mode sets to 2 by default.
mode: 0 - cursor left shift, no text shift
1 - no cursor shift, text right shift
2 - cursor right shift, no text shift
3 - no cursor shift, text left shift
*/
outb(inb(CONTROL) | 0x08, CONTROL);
lcd_write(0x04 + (mode%4));
}
void lcd_cursor(int cursor)
{
/*
set cursor: 0 - no cursor, no blink
1 - only blink, no cursor
2 - only cursor, no blink
3 - both cursor and blink
*/
outb(inb(CONTROL) | 0x08, CONTROL);
lcd_write( 0x0c + (cursor%4));
}
[/code]
clock.c (sample program)
[code]#include "lcd.h"
int main(void)
{
if (ioperm(PORTADDRESS, 3, 1)) {perror("ioperm"); return(1);}
time_t t;
struct tm *tm;
char msg[20];
char ft[20];
lcd_init();
lcd_goto(1,0);
t = time(NULL);
tm = localtime(&t);
strftime(ft, 20, " %Y-%m-%d", tm);
lcd_puts(ft);
while (1) {
lcd_goto(2,0);
t = time(NULL);
tm = localtime(&t);
strftime(ft, 20, " %H:%M:%S ", tm);
sprintf(msg, "%s", ft);
lcd_puts(msg);
usleep(200000);
}
}
[/code]
Makefile
[code]default: lcd
lcd: main.o lcd.o
gcc main.o lcd.o -o lcd
main.o: main.c
gcc -O -c main.c
lcd.o: lcd.c lcd.h
gcc -O -c lcd.c
clean :
- rm -f *.o
- rm -f lcd
- rm -f *~
[/code] 用windows + visual studio 有無問題 ???
CLCD also buy in 華輝? How much? CLCD 係 W Core 問呀蛇拎的!
上面全部 source 都係 complied from linux gcc and for linux
CLCD 果個可以試下改改佢…應該可以用 VS Compile!
另外 WinXP 唔比用 Program 直接 access hardware… [quote]原帖由 [i]閒魂[/i] 於 2007-2-27 14:24 發表
CLCD 係 W Core 問呀蛇拎的!
上面全部 source 都係 complied from linux gcc and for linux
CLCD 果個可以試下改改佢…應該可以用 VS Compile!
另外 WinXP 唔比用 Program 直接 access hardware… ... [/quote]
我都知WinXP #bad#
頁:
[1]