?? pcf8833.c
字號:
/*
\\\|///
\\ - - //
( @ @ )
+---------------------oOOo-(_)-oOOo-------------------------+
| |
| CPU.c |
| by Xiaoran Liu |
| 2005.3.16 |
| |
| ZERO research group |
| www.the0.net |
| |
| Oooo |
+----------------------oooO--( )--------------------------+
( ) ) /
\ ( (_/
\_)
*/
// 引入相關芯片的頭文件
#include <avr/io.h>
#include "PCF8833.h"
/*----------------------------------------------------------*\
| S1D15G00 Initialize |
\*----------------------------------------------------------*/
void S1D15G00SpiInit(void) {
// SPCR |= (1<<MSTR)|(1<<SPE)|(1<<CPOL)|(1<<CPHA);
// 設置SPI接口模式,MSTR=1,CPOL=1,CPHA=1,LSBF=0, fosc/4
// SPSR |= (1<<SPI2X);//SPI時鐘倍速
UCSRB |= (1<<TXEN)|(1<<UCSZ2)/*(1<<TXB8)*/;
//發送使能;
UBRRH = 0;
UBRRL = 0x0c;
UCSRC |= (1<<URSEL)|(1<<UMSEL)|(1<<UCSZ1)|(1<<UCSZ0)|(1<<UCPOL);
//同步模式;UCSZ2:UCSZ1:UCSZ0 9Bit模式
UCSRA |= (1<<MPCM);
/* while((UCSRA & (1<<UDRE))==0);
UCSRB &= ~(1<<TXB8);// bit8 = 0 : command
UDR=Data;
UCSRA|=(1<<UDRE);
while((UCSRA & (1<<UDRE))==0);
*/
}
/*----------------------------------------------------------*\
| S1D15G00 Write Command |
\*----------------------------------------------------------*/
void S1D15G00WriteCommand(INT8U Data) {
// INT16U temp=Data;
cbi(LCD_CR_PORT,LCD_CS);
sbi(LCD_CR_DDR, LCD_DATA); //set SDI.DDR = 1
cbi(LCD_CR_PORT, LCD_CS); //set CS = L
cbi(LCD_CR_PORT, LCD_CLK); //set SCK = L
cbi(LCD_CR_PORT, LCD_DATA); //send 0, for command
sbi(LCD_CR_PORT, LCD_CLK); //set SCK = H, latch data
//Bit 0(MSB)
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x80)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 1
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x40)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 2
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x20)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 3
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x10)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 4
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x08)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 5
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x04)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 6
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x02)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 7(LSB)
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x01)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//done
sbi(LCD_CR_PORT,LCD_CS);
}
/*----------------------------------------------------------*\
| S1D15G00 Write Data |
\*----------------------------------------------------------*/
void S1D15G00WriteData(INT8U Data) {
// INT16U temp=Data;
cbi(LCD_CR_PORT,LCD_CS);
sbi(LCD_CR_DDR, LCD_DATA); //set SDI.DDR = 1
cbi(LCD_CR_PORT, LCD_CS); //set CS = L
cbi(LCD_CR_PORT, LCD_CLK); //set SCK = L
sbi(LCD_CR_PORT, LCD_DATA); //send 1, for command
sbi(LCD_CR_PORT, LCD_CLK); //set SCK = H, latch data
//Bit 0(MSB)
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x80)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 1
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x40)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 2
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x20)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 3
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x10)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 4
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x08)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 5
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x04)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 6
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x02)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//Bit 7(LSB)
cbi(LCD_CR_PORT, LCD_CLK);
if(Data & 0x01)
sbi(LCD_CR_PORT, LCD_DATA);
else
cbi(LCD_CR_PORT, LCD_DATA);
sbi(LCD_CR_PORT, LCD_CLK);
//done
sbi(LCD_CR_PORT,LCD_CS);
}
/*----------------------------------------------------------*\
| S1D15G00 Set Page Area |
\*----------------------------------------------------------*/
void S1D15G00SetPageArea(char x1, char y1, char x2, char y2) {
S1D15G00WriteCommand(SET_X_ADDR);
S1D15G00WriteData(x1);
S1D15G00WriteData(x2);
S1D15G00WriteCommand(SET_Y_ADDR);
S1D15G00WriteData(y1);
S1D15G00WriteData(y2);
S1D15G00WriteCommand(MEM_WRITE);
}
/*----------------------------------------------------------*\
| S1D15G00 Clear LCD |
\*----------------------------------------------------------*/
void S1D15G00ClearLcd(void) {
unsigned int i;
S1D15G00SetPageArea(0, 0, GLCD_X_END, GLCD_Y_END);
// S1D15G00WriteCommand(RAMWR);
for(i=0; i<(GLCD_PIXELX*GLCD_PIXELY);i++)//(GLCD_PIXELX*GLCD_PIXELY)
{
S1D15G00WriteData(0xFF);
S1D15G00WriteData(0xFF);
}
}
/*----------------------------------------------------------*\
| Delay |
\*----------------------------------------------------------*/
void Delay(INT32U dly) {
INT32U i;
for(; dly>0; dly--)
for(i=0; i<50000; i++);
}
/*----------------------------------------------------------*\
| S1D15G00 Initial |
\*----------------------------------------------------------*/
void S1D15G00Init(void) {
sbi(LCD_CR_DDR,LCD_DATA);
sbi(LCD_CR_DDR,LCD_CS);
sbi(LCD_CR_DDR,LCD_CLK);
sbi(LCD_CR_DDR,LCD_RST);
sbi(LCD_CR_PORT,LCD_CS);
Delay(1);
cbi(LCD_CR_PORT,LCD_RST);
Delay(6);
sbi(LCD_CR_PORT,LCD_RST);
Delay(6);
sbi(LCD_CR_PORT,LCD_DATA);
sbi(LCD_CR_PORT,LCD_CLK);
Delay(6);
// S1D15G00SpiInit();
S1D15G00WriteCommand(SOFT_RESET); //Temperature gradient set
S1D15G00WriteCommand(BOOSTER_ON); //Internal oscillation on
S1D15G00WriteCommand(SLEEP_OUT); //Sleep out
S1D15G00WriteCommand(COLOR_INTERFACE); //Partial display out
S1D15G00WriteData(COLOR_16_BIT);
S1D15G00WriteCommand(COLOR_SET); //256-color position set
S1D15G00WriteData(0x00);
S1D15G00WriteData(0x02);
S1D15G00WriteData(0x04);
S1D15G00WriteData(0x06);
S1D15G00WriteData(0x09);
S1D15G00WriteData(0x0B);
S1D15G00WriteData(0x0D);
S1D15G00WriteData(0x0F);
S1D15G00WriteData(0x00);
S1D15G00WriteData(0x02);
S1D15G00WriteData(0x04);
S1D15G00WriteData(0x06);
S1D15G00WriteData(0x09);
S1D15G00WriteData(0x0B);
S1D15G00WriteData(0x0D);
S1D15G00WriteData(0x0F);
S1D15G00WriteData(0x00);
S1D15G00WriteData(0x04);
S1D15G00WriteData(0x0B);
S1D15G00WriteData(0x0F);
S1D15G00WriteCommand(MEM_CONTROL); //Display control
S1D15G00WriteData((0 << MEM_MX) | (1 << MEM_MY) | (1 << MEM_RGB) | (0 << MEM_VW) | (0 << MEM_LAO));
Delay(60);
S1D15G00WriteCommand(DISPLAY_ON); //Display control
}
#include "8X16.h"
void PutChar(INT8U x, INT8U y, char c, INT16U f, INT16U b) {
unsigned int i,j;
INT8U fRed,fGreenBlue,bRed,bGreenBlue;
fRed = (f>>8) & 0xFF; fGreenBlue = f & 0xFF;
bRed = (b>>8) & 0xFF; bGreenBlue = b & 0xFF;
S1D15G00SetPageArea(x, y, x+8-1, y+16-1);
for(i=0; i<16;i++) {
INT8U m=pgm_read_byte(font+c*16+i);
for(j=0;j<8;j++) {
if((m&0x80)==0x80) {
S1D15G00WriteData(fRed);
S1D15G00WriteData(fGreenBlue);
}
else {
S1D15G00WriteData(bRed);
S1D15G00WriteData(bGreenBlue);
}
m<<=1;
}
}
}
void PutString(INT8U x, INT8U y, char *s, INT16U f, INT16U b) {
INT8U l=0;
while(*s) {
PutChar(x+l*8,y,*s,f,b);
s++;l++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -