Witam,
mam moduł lcd podany w temacie i próbuję uruchomić go za pomocą uC PIC. Poniżej kod:
[syntax=c]/** C O N F I G U R A T I O N B I T S ******************************/
//najnowszy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#pragma config FOSC = INTIO67
#pragma config WDTEN = OFF, LVP = OFF, MCLRE = OFF
/** I N C L U D E S **************************************************/
#include "p18f45k20.h"
#include <delays.h>
#define LCD_Reset LATCbits.LATC0 // LCD_Reset
#define MOSI LATCbits.LATC5 // DX0 output
#define CLK LATCbits.LATC3 // CLK output
#define CS LATCbits.LATC7 // CS output
/** D E C L A R A T I O N S ******************************************/
void InitLcdNokia(void);
/** pozniej do pliku naglowkowego .h **/
#define WHITE 0xFFF
#define BLACK 0x000
#define RED 0xF00
#define GREEN 0x0F0
#define BLUE 0x00F
#define CYAN 0x1FF
#define MAGENTA 0xF0F
#define YELLOW 0xFF0
#define GRAY 0x222
#define LIGHTBLUE 0xADE
#define PINK 0xF6A
// Philips PCF8833 LCD controller command codes
#define NOP 0x00 // nop
#define SWRESET 0x01 // software reset
#define BSTROFF 0x02 // booster voltage OFF
#define BSTRON 0x03 // booster voltage ON
#define RDDIDIF 0x04 // read display identification
#define RDDST 0x09 // read display status
#define SLEEPIN 0x10 // sleep in
#define SLEEPOUT 0x11 // sleep out
#define PTLON 0x12 // partial display mode
#define NORON 0x13 // display normal mode
#define INVOFF 0x20 // inversion OFF
#define INVON 0x21 // inversion ON
#define DALO 0x22 // all pixel OFF
#define DAL 0x23 // all pixel ON
#define SETCON 0x25 // write contrast
#define DISPOFF 0x28 // display OFF
#define DISPON 0x29 // display ON
#define CASET 0x2A // column address set
#define PASET 0x2B // page address set
#define RAMWR 0x2C // memory write
#define RGBSET 0x2D // colour set
#define PTLAR 0x30 // partial area
#define VSCRDEF 0x33 // vertical scrolling definition
#define TEOFF 0x34 // test mode
#define TEON 0x35 // test mode
#define MADCTL 0x36 // memory access control
#define SEP 0x37 // vertical scrolling start address
#define IDMOFF 0x38 // idle mode OFF
#define IDMON 0x39 // idle mode ON
#define COLMOD 0x3A // interface pixel format
#define SETVOP 0xB0 // set Vop
#define BRS 0xB4 // bottom row swap
#define TRS 0xB6 // top row swap
#define DISCTR 0xB9 // display control
#define DOR2 0xBA // data order
#define TCDFE 0xBD // enable/disable DF temperature compensation
#define TCVOPE 0xBF // enable/disable Vop temp comp
#define EC 0xC0 // internal or external oscillator
#define SETMUL 0xC2 // set multiplication factor
#define TCVOPAB 0xC3 // set TCVOP slopes A and B
#define TCVOPCD 0xC4 // set TCVOP slopes c and d
#define TCDF 0xC5 // set divider frequency
#define DF8COLOR 0xC6 // set divider frequency 8-color mode
#define SETBS 0xC7 // set bias system
#define RDTEMP 0xC8 // temperature read back
#define NLI 0xC9 // n-line inversion
void WriteSpiData(unsigned char data);
void InitLcdNokia(void);
void SetContrast(unsigned char con);
void ClsLCD(short color);
void delay_50ms(void);
void WriteSpiCommand(unsigned char command);
void clock_8bit(unsigned char bits_in);
void WriteSpiCommand(unsigned char command)
{
CLK=0; // ustaw SCLK w stan niski
CS=1; // CS=0
MOSI=0; // command 0
clock_8bit(command);
}
void clock_8bit(unsigned char bits_in)
{
unsigned char bitcnt;
CLK=1;
for (bitcnt = 8; bitcnt >0; bitcnt--)
{
CLK=0; // CLK=0 // ustaw SCLK w stan niski
if ((bits_in&0x80)==1)
MOSI=1; // MSB goes first
else
MOSI=0; // MSB goes first
CLK=1; // CLK=1 // ustaw SCLK w stan wysoki
bits_in = bits_in << 1; // Logical shift data by 1 bit left
}
CS=0;
}
void WriteSpiData(unsigned char data)
{
CLK=0; // ustaw SCLK w stan niski
CS=1; // CS=0
MOSI=1; // dane 1
clock_8bit(data);
}
void InitLcdNokia(void)
{
int i;
// Hardware reset
// linie interfejsu SPI inicjowane w stan wysoki
CS=1;
CLK=0;
MOSI=0;
LCD_Reset = 0; // Reset nieaktywny
delay_50ms();
LCD_Reset = 1; // Reset wyswietlacza aktywny
delay_50ms();
LCD_Reset = 0; // Reset nieaktywny
delay_50ms();
// Software reset
WriteSpiCommand(SWRESET);
delay_50ms();
// Sleep out
WriteSpiCommand(SLEEPOUT);
// Inversion on (command 0x20)
WriteSpiCommand(NORON);
WriteSpiCommand(BSTRON); //BoostON
// Memory access controler (command 0x36)
WriteSpiCommand(MADCTL);
WriteSpiData(0xF0);
//contrast - write_contrast (command 0x25)
WriteSpiCommand(SETCON); //SETCON
WriteSpiData(0x3a); //contrast 0x30
delay_50ms();
// Display On (command 0x29)
WriteSpiCommand(DISPON);
// Color Interface Pixel Format (command 0x3A)
WriteSpiCommand(COLMOD);
WriteSpiData(0x03); // 0x03 = 12 bits-per-pixel
WriteSpiCommand(NOP);
}
// This function sets contrast. con should be value in range <-64...63>
void SetContrast(unsigned char con)
{
WriteSpiCommand(SETCON);
WriteSpiData(con);
}
void ClsLCD(short color) {
int i;
// ustawienie zakresu zmian licznika adresowego stron pamięci
WriteSpiCommand(PASET);
WriteSpiData(0); //adres początkowy
WriteSpiData(131); //adres końcowy
// ustawienie zakresu zmian licznika adresowego kolumn
WriteSpiCommand(CASET);
WriteSpiData(0); //adres początkowy
WriteSpiData(131); //adres końcowy
// zapisanie pamięci kolorem z
WriteSpiCommand(RAMWR);
for(i = 0; i < ((131 * 131) / 2); i++) {
WriteSpiData((color >> 4) & 0xFF); //kopiowanie 12 bitów dla jednego piksela na 24 bity dla 2 pikseli
WriteSpiData(((color & 0xF) << 4) | ((color >> 8) & 0xF));
WriteSpiData(color & 0xFF);
}
i=1;
}
void delay_50ms(void){
Delay10KTCYx(10); //czekaj 100ms - fcy=0,5us *10 000 = 5ms * 10 = 50ms
}
void main (void)
{
int i,k,l;
unsigned char status;
TRISD = 0b00000000; // PORTD bit 7 to output (0); bits 6:0 are inputs (1)
//LATDbits.LATD5 = 5;
TRISC = 0b00000000; // PORTD bits 7:0 are all outputs (0)
//TRISCbits.TRISC7 = 1; // is input
OSCCON = 0x60; // IRCFx = 110 8MHz
OSCTUNEbits.PLLEN = 0; // x4 PLL disabled
test();
InitLcdNokia();
ClsLCD(GREEN);
ClsLCD(WHITE);
ClsLCD(BLACK);
while (1)
{
;
}
}
void delay()
{
int i;
for (i=0;i<32000;i++)
;
}[/syntax]
Niestety program nie działa. Sterownik na 99% PCF8833 Philipsa.
Czy ktoś dostrzega jakiś błąd w moim kodzie?
Opis wyprowadzeń ze strony producenta Kamodtft2
Nr styku Nazwa Opis Kierunek
1 CLK Sygnał zegarowy taktujący dane na linii DIN Wejście
2 GND Masa zasilania Zasilanie
3 DIN Wejście danych synchronizowane sygnałem CLK Wejście
4 – – –
5 – – –
6 – – –
7 RES Sygnał zerowania (aktywny stan wysoki) Wejście - czy to oznacza, że aktywowanie sygnału Reset urządzenia jest za pomocą stanu wysokiego na linii?
8 – – –
9 +V Zasilanie 3,3 lub 5 VDC Zasilanie
10 SCE Wejście aktywujące interfejs szeregowy (aktywny stan wysoki) Wejście - czy to oznacza, że wybór aktynego urządzenia jest za pomocą stanu wysokiego na linii? pytam ponieważ program nie działa, próbowałem z dwoma opcjami ale efekt jest taki sam.
W programie próbuję zapalić wszystkie piksele wyświetlacza na 3 różne kolory.
Czy komuś udało się uruchomić ten moduł ?