PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : Ks0108.h



naruto
25-02-2011, 00:58
با عرض سلام و خسته نباشید . برنامه زیر رو برای AVR نوشته بودم و جواب داده بود با کمی تغییرات می خواستم برای ARM استفاده کنم ولی کلی ERORR داد و کامپایل نشد . برنامه داخل مجله هم جواب نداد
مطف میکنید برنامه را بررسی کنید
با تشکر

#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "font.h"
#include "pio.h"
#include "delay.h"

typedef unsigned char byte;
//----------------------
#define cols 128;
#define rows 64;
#define E_DELAY 3;
#define DATAPORT PORTB
#define RS PA0
#define RW PA1
#define EN PA2
#define CS1 PA3
#define CS2 PA4

#define A 0XFF;
#define B 0XFF;
#ifndef KS0108_H
PORTB_OUTPUT=B;
PORTA_OUTPUT=A;

//--------Arabic----------
static int prevLet = 193;
static byte stat = 0;
static byte prevX = 0;
static byte prevY = 0;
//------------------------
void trigger()
{
SET_PORTA=EN ; //EN=1 high
delay_us(E_DELAY);
RST_PORTA=EN ; //EN=0 low
delay_us(E_DELAY);
}
//------------------------
void glcd_on()
{
SET_PORTA=CS1 ; //CS1 = 1
SET_PORTA=CS2 ; //CS2 = 1
RST_PORTA=RS ; // RS = 0 low --> command
RST_PORTA=RW ; // RW = 0 low --> write
DATAPORT = 0x3F; //ON command
trigger();
}
//----------------------
void glcd_off()
{
SET_PORTA=CS1 ; //CS1 = 1
SET_PORTA=CS2 ; //CS2 = 1
RST_PORTA=RS ; // RS = 0 low --> command
RST_PORTA=RW ; // RW = 0 low --> write
DATAPORT = 0x3E; //OFF command
trigger();
}
//----------------------
void set_start_line(byte line)
{
RST_PORTA=RS ; // RS = 0 low --> command
RST_PORTA=RW ; // RW = 0 low --> write
SET_PORTA=CS1 ; //CS1 = 1
SET_PORTA=CS2 ; //CS2 = 1
DATAPORT = 0xC0 | line; //Set Start Line command
trigger();
}
//----------------------
void goto_col(unsigned int x)
{
byte pattern;
RST_PORTA=RS ; // RS = 0 low --> command
RST_PORTA=RW ; // RW = 0 low --> write
if(x<64) //left section
{
SET_PORTA=CS1 ; //CS1 = 1
RST_PORTA=CS2 ; //CS2 = 0
pattern = x; //put column address on data port
}
else //right section
{
RST_PORTA=CS1 ; //CS1 = 0
SET_PORTA=CS2 ; //CS2 = 1
pattern = x-64; //put column address on data port
}
pattern = (pattern | 0x40 ) & 0x7F; //Command format
DATAPORT = pattern;
trigger();
}
//----------------------
void goto_row(unsigned int y)
{
byte pattern;
RST_PORTA=RS ; // RS = 0 low --> command
RST_PORTA=RW ; // RW = 0 low --> write
pattern = (y | 0xB8 ) & 0xBF; //put row address on data port set command
DATAPORT = pattern;
trigger();
}
//----------------------
void goto_xy(unsigned int x,unsigned int y)
{
goto_col(x);
goto_row(y);
}
//----------------------
void glcd_write(byte b)
{
SET_PORTA=RS ; // RS = 1 high --> data
RST_PORTA=RW ; // RW = 0 low --> write
DATAPORT = b; //put data on data port
delay_us(1);
trigger();
}
//------------------------
void glcd_clrln(byte ln)
{
int i;
for(i=0;i<128;i++)
{
goto_col(i);
goto_row(ln);
glcd_write(0);
}
}
//-------------------------
void glcd_clear()
{
int i;
for(i=0;i<1024;i++)
{
goto_col(i%128);
goto_row(i/128);
glcd_write(0);
}
}
//------------Arabic/English Writing-------
void putIt(int c,int x,int y)
{
byte i;
goto_col(x);
goto_row(y);
for(i=0;i<8;i++)
{
glcd_write(font[(8*c)+i]);
}
}
//--------------------------
void glcd_putchar(byte c,int x,int y,byte l)
{
if(l == 1)
{
if((map[prevLet-193][5]) && (map[c-193][4]) && (c >= 193) && (prevLet >= 193))
{
putIt(map[prevLet-193][stat+1],prevX,prevY);
stat = 2;
}else stat = 0;

if(c >= 193) putIt(map[c-193][stat],x,y);
else putIt(c,x,y);

prevLet = c;
prevX = x;
prevY = y;

}else putIt(c,x,y);
}
//---------------------------
void glcd_puts(byte *c,int x,int y,unsigned char l)
{
char i = 0;
char special = 0;
while((i<strlen(c)) && l==0)
{
glcd_putchar(*(c+i),x,y,0);
x += 8;
if(x>=128)
{
x=0;
y++;
}
i++;
}

while((i<strlen(c)) && l==1)
{
if((*(c+i) == 225) && (*(c+i+1) == 199))
special = 249;
else if((*(c+i) == 225) && (*(c+i+1) == 195))
special = 231;
else if((*(c+i) == 225) && (*(c+i+1) == 194))
special = 232;
else if((*(c+i) == 225) && (*(c+i+1) == 197))
special = 233;
if(special)
{
glcd_putchar(special,x,y,1);
i+=2;
x -= 8;
special = 0;
continue;
}
glcd_putchar(*(c+i),x,y,l);
x -= 8;
if(x < 0)
{
x=120;
y++;
}
i++;
}
prevLet = 193;
}

#endif

naruto
25-02-2011, 01:01
این برنامه داخل هدر فایل GLCD یعنی Ks0108.h نوشته شده