|
|
View previous topic :: View next topic |
Author |
Message |
Alison
Joined: 30 Aug 2011 Posts: 5 Location: France
|
PIC16F887 + 128x160 LCD |
Posted: Tue Aug 30, 2011 4:46 am |
|
|
Hello guys, I use the PIC16F887 and a 128x160 LCD http://www.newhavendisplay.com/index.php?main_page=product_info&cPath=1_589&products_id=2214
I found the LCD's program on the constructor website :
Code: | /*****************************************************/
/*
NHD-1-8-128160ZF.c
Program for writing to Newhaven Display 1.8" TFT
(c)2009 Curt Lagerstam - Newhaven Display International, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/*****************************************************/
#include <REG52.H>
#include "picture.h"
/*****************************************************/
#define CS PIN_B0 //Chip select
#define RS PIN_B1 //Data/Instruction Register select
#define WR1 PIN_B2 //Write
#define RD1 PIN_B3 //Read
#define RESET PIN_B4 //Reset
/*****************************************************/
void delay(unsigned int n) //Delay subroutine
{
unsigned int i,j;
for (i=0;i<n;i++)
for (j=0;j<350;j++)
{;}
}
/*****************************************************/
void data_out(unsigned char i) //Data Output 8-bit Bus Interface
{
output_high(RS); //Data register
output_high(RD1); //Read disable
output_low(WR1); //Write enable
P1 = i; //put byte on port 1
//nop
output_high(WR1); //Clock in data
}
void comm_out(unsigned char j) //Command Output 8-bit Bus Interface
{
output_low(RS); //Instruction register
output_high(RD1); //Read disable
output_low(WR1); //Write enable
P1 = j; //put byte on port 1
//nop
output_high(WR1); //Clock in data
}
/*****************************************************/
void Fulldisplay(unsigned char d1,unsigned char d2)//Fill display with RGB color
{
int i,j;
output_high(RS); //Data register
for(i=0;i<160;i++) //160 lines
{
for(j=0;j<128;j++) //128pixels/line
{
P1 = d1; //high 8bits
output_low(WR1);
//nop
output_high(WR1); //clock in data
P1 = d2; //low 8 bits
output_low(WR1);
//nop
output_high(WR1); //clock in data
}
}
}
/*****************************************************/
void dispPic(unsigned char *lcd_string) //show 16bpp bitmap, 128x107pixels
{
int i,j;
output_high(RS); //Data register
for(i=0;i<26;i++) //MAY REMOVE THIS LOOP - write 26 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
P1 = 0x00;
output_low(WR1);
//nop
output_high(WR1);
}
}
for(i=0;i<107;i++) //MAY CHANGE TO i<160 - write 107 lines of picture data
{
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip first 56bytes
for(j=0;j<128;j++) //Write 128pixels/line
{
P1 = *lcd_string;//put high 8bits on port 1
output_low(WR1);
//nop
output_high(WR1); //Clock in data
P1 = *(++lcd_string);//put low 8bits on port 1
output_low(WR1);
//nop
output_high(WR1); //Clock in data
lcd_string++; //point to next byte of picture data
}
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip last 56bytes also
}
for(i=0;i<27;i++) //MAY REMOVE THIS LOOP - write 27 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
P1 = 0x00;
output_low(WR1);
//nop
output_high(WR1);
}
}
}
/****************************************************/
void displayQuads() //split the display into quadrants of different colors
{
int i,j;
output_high(RS); //Data register
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0x00;
output_low(WR1);
//nop
output_high(WR1);
P1 = 0x1F; //0x00,0x1F = Blue
output_low(WR1);
//nop
output_high(WR1);
}
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0xF8;
output_low(WR1);
//nop
output_high(WR1);
P1 = 0x00; //0xF8,0x00 = Red
output_low(WR1);
//nop
output_high(WR1);
}
}
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0xFF;
output_low(WR1);
//nop
output_high(WR1);
P1 = 0xE0; //0xFF,0xE0 = Yellow
output_low(WR1);
//nop
output_high(WR1);
}
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0x07;
output_low(WR1);
//nop
output_high(WR1);
P1 = 0xE0; //0x07,0xE0 = Green
output_low(WR1);
//nop
output_high(WR1);
}
}
}
/****************************************************
* Initialization For ILI9163 *
*****************************************************/
void resetLCD()
{
output_low(RESET);
delay(100);
output_high(RESET);
delay(100);
}
void init_LCD()
{
output_low(CS); //Chip Select = Active
comm_out(0x11); //exit sleep mode
delay(100);
comm_out(0x26); data_out(0x04); //set gamma curve 3
comm_out(0xF2); data_out(0x00); //gamma adjustment enabled
comm_out(0xB1); data_out(0x0A); data_out(0x14); //frame rate
comm_out(0xC0); data_out(0x0A); data_out(0x00); //power control 1
comm_out(0xC1); data_out(0x02); //power control 2
comm_out(0xC5); data_out(0x2F); data_out(0x3E); //VCOM control 1
comm_out(0xC7); data_out(0x40); //VCOM offset control
comm_out(0x2A); //column address set
data_out(0x00);
data_out(0x00); //start column 0x0000
data_out(0x00);
data_out(0x7F); //end column 0x007F = 127
comm_out(0x2B); //page address set
data_out(0x00);
data_out(0x00); //start line 0x0000
data_out(0x00);
data_out(0x9F); //end line 0x009F = 159
comm_out(0x36); data_out(0xC0); //Memory access control
comm_out(0x3A); data_out(0xC5); //Pixel format = 16bit/pixel
comm_out(0x29); //display on
comm_out(0x2C); //write to frame memory(begin writing data)
}
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
int main(void)
{
P1 = 0;
resetLCD();
init_LCD();
while(1) //continue
{
displayQuads(); //color quadrants
delay(2000);
Fulldisplay(0xF8,0x00); //Red
delay(1500);
Fulldisplay(0x07,0xE0); //Green
delay(1500);
Fulldisplay(0x00,0x1F); //Blue
delay(1500);
Fulldisplay(0xFF,0xFF); //White
delay(1500);
Fulldisplay(0x00,0x00); //Black
delay(1500);
dispPic(picture); //16bpp bitmap
delay(2000);
}
} |
But I don't understand some instructions :
Code: | #include <REG52.H>
#include "picture.h" |
and Code: | P1 = j; //put byte on port 1
P1 = d1; //high 8bits
P1 = 0xF8;
|
I need your help to translate this piece of code to CCS code
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Aug 30, 2011 5:05 am |
|
|
ok...
#include <REG52.H>
#include "picture.h"
these are 'header' files. They contain specific code that is required for the 'main program to run.Typically it will contain the I/O pin designations(what pin does what),data specific to this PIC,default varibles(true=1, flase=0),etc.
I suspect the second one to be a test picture to confirm the program is running correctly, the first may contain setup details.
***
P1 = j; //put byte on port 1
P1 = d1; //high 8bits
P1 = 0xF8;
These statements send 8 bit data to PORTA of the PIC, IF we assume that P1 has been defined as being memory location 0x05! If P1 was defined as 6, all data would go to PORT B.
If j was equal to 0xF0 then bits 7,6,5,4 would be high, bits 3,2,1,0 would be set low.
If you insert this line near the beginning of the program..say just after the 'defines' section
#byte P1 = 5
then
P1=J;
would send the data held in variable J to the PIC port A.
hth
jay |
|
|
Alison
Joined: 30 Aug 2011 Posts: 5 Location: France
|
|
Posted: Tue Aug 30, 2011 6:29 am |
|
|
Thank you for your answer temtronic, you helped me a lot !
But I have one more problem : The header file #include <REG52.H> isn't in the CCS library so, I searched on the web and I found that : http://www.keil.com/dd/docs/c51/reg52.h
Unfortunately I don't understand this programming language...
Is anybody knows where I can find this header file in CCS language? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Aug 30, 2011 8:40 am |
|
|
Alison wrote: | But I have one more problem : The header file #include <REG52.H> isn't in the CCS library so, I searched on the web and I found that : http://www.keil.com/dd/docs/c51/reg52.h
...Is anybody knows where I can find this header file in CCS language? |
That file is a processor specific header for the Intel 80C52/80C32 8051 derived microcontrollers. The equivalent in CCS is the 16F887.h file that's already included in your code. REG52.h does explain the
Code: | P1 = j; //put byte on port 1
P1 = d1; //high 8bits
P1 = 0xF8;" |
code. P1 is a port defined in the file. You have to replace "P1" and everything like it in the code, i.e. those defined as sfr, with the ports you are using in your hardware. The sbit definitions map individual bits of the ports. You will have to translate these into the equivalent on your hardware.
I notice you, or someone else, has commented out all the nops in the code. These nops would have added no-operation instructions to ensure correct timing of the hardware signals. Depending on the speed of your PIC and the speed at which the original processor will have run, you may need to carefully modify these timing critical delays to match the display hardware. Look at the data sheets very carefully! No operations may not do "anything" but what they actually do is stall the processor for one instruction period, giving a short but known time delay.
RF Developer |
|
|
Alison
Joined: 30 Aug 2011 Posts: 5 Location: France
|
|
Posted: Wed Aug 31, 2011 4:07 am |
|
|
HI!
This code is the original program that I found on the constructor's website :
Code: | #include <REG52.H>
#include "picture.h"
/*****************************************************/
sbit CS = P3^0; //Chip select
sbit RS = P3^7; //Data/Instruction Register select
sbit WR1 = P3^4; //Write
sbit RD1 = P3^6; //Read
sbit RESET = P3^1; //Reset
/*****************************************************/
void delay(unsigned int n) //Delay subroutine
{
unsigned int i,j;
for (i=0;i<n;i++)
for (j=0;j<350;j++)
{;}
}
/*****************************************************/
void data_out(unsigned char i) //Data Output 8-bit Bus Interface
{
RS = 1; //Data register
RD1 = 1; //Read disable
WR1 = 0; //Write enable
P1 = i; //put byte on port 1
//nop
WR1 = 1; //Clock in data
}
void comm_out(unsigned char j) //Command Output 8-bit Bus Interface
{
RS = 0; //Instruction register
RD1 = 1; //Read disable
WR1 = 0; //Write enable
P1 = j; //put byte on port 1
//nop
WR1 = 1; //Clock in data
}
/*****************************************************/
void Fulldisplay(unsigned char d1,unsigned char d2)//Fill display with RGB color
{
int i,j;
RS = 1; //Data register
for(i=0;i<160;i++) //160 lines
{
for(j=0;j<128;j++) //128pixels/line
{
P1 = d1; //high 8bits
WR1 = 0;
//nop
WR1 = 1; //clock in data
P1 = d2; //low 8 bits
WR1 = 0;
//nop
WR1 = 1; //clock in data
}
}
}
/*****************************************************/
void dispPic(unsigned char *lcd_string) //show 16bpp bitmap, 128x107pixels
{
int i,j;
RS = 1; //Data register
for(i=0;i<26;i++) //MAY REMOVE THIS LOOP - write 26 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
P1 = 0x00;
WR1 = 0;
//nop
WR1 = 1;
}
}
for(i=0;i<107;i++) //MAY CHANGE TO i<160 - write 107 lines of picture data
{
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip first 56bytes
for(j=0;j<128;j++) //Write 128pixels/line
{
P1 = *lcd_string;//put high 8bits on port 1
WR1 = 0;
//nop
WR1 = 1; //Clock in data
P1 = *(++lcd_string);//put low 8bits on port 1
WR1 = 0;
//nop
WR1 = 1; //Clock in data
lcd_string++; //point to next byte of picture data
}
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip last 56bytes also
}
for(i=0;i<27;i++) //MAY REMOVE THIS LOOP - write 27 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
P1 = 0x00;
WR1 = 0;
//nop
WR1 = 1;
}
}
}
/****************************************************/
void displayQuads() //split the display into quadrants of different colors
{
int i,j;
RS = 1; //Data register
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0x00;
WR1 = 0;
//nop
WR1 = 1;
P1 = 0x1F; //0x00,0x1F = Blue
WR1 = 0;
//nop
WR1 = 1;
}
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0xF8;
WR1 = 0;
//nop
WR1 = 1;
P1 = 0x00; //0xF8,0x00 = Red
WR1 = 0;
//nop
WR1 = 1;
}
}
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0xFF;
WR1 = 0;
//nop
WR1 = 1;
P1 = 0xE0; //0xFF,0xE0 = Yellow
WR1 = 0;
//nop
WR1 = 1;
}
for(j=0;j<64;j++){ //64 pixels wide
P1 = 0x07;
WR1 = 0;
//nop
WR1 = 1;
P1 = 0xE0; //0x07,0xE0 = Green
WR1 = 0;
//nop
WR1 = 1;
}
}
}
/****************************************************
* Initialization For ILI9163 *
*****************************************************/
void resetLCD()
{
RESET = 0;
delay(100);
RESET = 1;
delay(100);
}
void init_LCD()
{
CS = 0; //Chip Select = Active
comm_out(0x11); //exit sleep mode
delay(100);
comm_out(0x26); data_out(0x04); //set gamma curve 3
comm_out(0xF2); data_out(0x00); //gamma adjustment enabled
comm_out(0xB1); data_out(0x0A); data_out(0x14); //frame rate
comm_out(0xC0); data_out(0x0A); data_out(0x00); //power control 1
comm_out(0xC1); data_out(0x02); //power control 2
comm_out(0xC5); data_out(0x2F); data_out(0x3E); //VCOM control 1
comm_out(0xC7); data_out(0x40); //VCOM offset control
comm_out(0x2A); //column address set
data_out(0x00);
data_out(0x00); //start column 0x0000
data_out(0x00);
data_out(0x7F); //end column 0x007F = 127
comm_out(0x2B); //page address set
data_out(0x00);
data_out(0x00); //start line 0x0000
data_out(0x00);
data_out(0x9F); //end line 0x009F = 159
comm_out(0x36); data_out(0xC0); //Memory access control
comm_out(0x3A); data_out(0xC5); //Pixel format = 16bit/pixel
comm_out(0x29); //display on
comm_out(0x2C); //write to frame memory(begin writing data)
}
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
int main(void)
{
P1 = 0;
resetLCD();
init_LCD();
while(1) //continue
{
displayQuads(); //color quadrants
delay(2000);
Fulldisplay(0xF8,0x00); //Red
delay(1500);
Fulldisplay(0x07,0xE0); //Green
delay(1500);
Fulldisplay(0x00,0x1F); //Blue
delay(1500);
Fulldisplay(0xFF,0xFF); //White
delay(1500);
Fulldisplay(0x00,0x00); //Black
delay(1500);
dispPic(picture); //16bpp bitmap
delay(2000);
}
} |
And this code is the program that I made thanks to you :
Code: | #include <16F887.h>
#FUSES HS,NOWDT
#use delay (clock=8000000)
#include <picture.h>
#define CS PIN_A0 //Chip select
#define RS PIN_A1 //Data/Instruction Register select
#define WR1 PIN_A2 //Write
#define RD1 PIN_A3 //Read
#define RESET PIN_A4 //Reset
/*****************************************************/
void delay(unsigned int n) //Delay subroutine
{
unsigned int i,j;
for (i=0;i<n;i++)
for (j=0;j<350;j++)
{;}
}
/*****************************************************/
void data_out(unsigned char i) //Data Output 8-bit Bus Interface
{
output_high(RS); //Data register
output_high(RD1); //Read disable
output_low(WR1); //Write enable
output_B(i); //put byte on port 1
//nop
output_high(WR1); //Clock in data
}
void comm_out(unsigned char j) //Command Output 8-bit Bus Interface
{
output_low(RS); //Instruction register
output_high(RD1); //Read disable
output_low(WR1); //Write enable
output_B(j); //put byte on port 1
//nop
output_high(WR1); //Clock in data
}
/*****************************************************/
void Fulldisplay(unsigned char d1,unsigned char d2)//Fill display with RGB color
{
int i,j;
output_high(RS); //Data register
for(i=0;i<160;i++) //160 lines
{
for(j=0;j<128;j++) //128pixels/line
{
output_B(d1); //high 8bits
output_low(WR1);
//nop
output_high(WR1); //clock in data
output_B(d2); //low 8 bits
output_low(WR1);
//nop
output_high(WR1); //clock in data
}
}
}
/*****************************************************/
void dispPic(unsigned char *lcd_string) //show 16bpp bitmap, 128x107pixels
{
int i,j;
output_high(RS); //Data register
for(i=0;i<26;i++) //MAY REMOVE THIS LOOP - write 26 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
output_B(0x00);
output_low(WR1);
//nop
output_high(WR1);
}
}
for(i=0;i<107;i++) //MAY CHANGE TO i<160 - write 107 lines of picture data
{
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip first 56bytes
for(j=0;j<128;j++) //Write 128pixels/line
{
// P1 = *lcd_string;//put high 8bits on port 1
output_low(WR1);
//nop
output_high(WR1); //Clock in data
// P1 = *(++lcd_string);//put low 8bits on port 1
output_low(WR1);
//nop
output_high(WR1); //Clock in data
lcd_string++; //point to next byte of picture data
}
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip last 56bytes also
}
for(i=0;i<27;i++) //MAY REMOVE THIS LOOP - write 27 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
output_B(0x00);
output_low(WR1);
//nop
output_high(WR1);
}
}
}
/****************************************************/
void displayQuads() //split the display into quadrants of different colors
{
int i,j;
output_high(RS); //Data register
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
output_B(0x00);
output_low(WR1);
//nop
output_high(WR1);
output_B(0x1F); //0x00,0x1F = Blue
output_low(WR1);
//nop
output_high(WR1);
}
for(j=0;j<64;j++){ //64 pixels wide
output_B(0xF8);
output_low(WR1);
//nop
output_high(WR1);
output_B(0x00); //0xF8,0x00 = Red
output_low(WR1);
//nop
output_high(WR1);
}
}
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
output_B(0xFF);
output_low(WR1);
//nop
output_high(WR1);
output_B(0xE0); //0xFF,0xE0 = Yellow
output_low(WR1);
//nop
output_high(WR1);
}
for(j=0;j<64;j++){ //64 pixels wide
output_B(0x07);
output_low(WR1);
//nop
output_high(WR1);
output_B(0xE0); //0x07,0xE0 = Green
output_low(WR1);
//nop
output_high(WR1);
}
}
}
/****************************************************
* Initialization For ILI9163 *
*****************************************************/
void resetLCD()
{
output_low(RESET);
delay(100);
output_high(RESET);
delay(100);
}
void init_LCD()
{
output_low(CS); //Chip Select = Active
comm_out(0x11); //exit sleep mode
delay(100);
comm_out(0x26); data_out(0x04); //set gamma curve 3
comm_out(0xF2); data_out(0x00); //gamma adjustment enabled
comm_out(0xB1); data_out(0x0A); data_out(0x14); //frame rate
comm_out(0xC0); data_out(0x0A); data_out(0x00); //power control 1
comm_out(0xC1); data_out(0x02); //power control 2
comm_out(0xC5); data_out(0x2F); data_out(0x3E); //VCOM control 1
comm_out(0xC7); data_out(0x40); //VCOM offset control
comm_out(0x2A); //column address set
data_out(0x00);
data_out(0x00); //start column 0x0000
data_out(0x00);
data_out(0x7F); //end column 0x007F = 127
comm_out(0x2B); //page address set
data_out(0x00);
data_out(0x00); //start line 0x0000
data_out(0x00);
data_out(0x9F); //end line 0x009F = 159
comm_out(0x36); data_out(0xC0); //Memory access control
comm_out(0x3A); data_out(0xC5); //Pixel format = 16bit/pixel
comm_out(0x29); //display on
comm_out(0x2C); //write to frame memory(begin writing data)
}
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
int main(void)
{
output_B(0x00);
resetLCD();
init_LCD();
while(1) //continue
{
displayQuads(); //color quadrants
delay(2000);
Fulldisplay(0xF8,0x00); //Red
delay(1500);
Fulldisplay(0x07,0xE0); //Green
delay(1500);
Fulldisplay(0x00,0x1F); //Blue
delay(1500);
Fulldisplay(0xFF,0xFF); //White
delay(1500);
Fulldisplay(0x00,0x00); //Black
delay(1500);
dispPic(picture); //16bpp bitmap
delay(2000);
}
} |
When I compile the second code with CCS, I have 5 Warnings :
>>> Warning 203 "main.c" Line 17(1,1): Condition always TRUE
>>> Warning 203 "main.c" Line 68(1,1): Condition always TRUE
>>> Warning 203 "main.c" Line 97(1,1): Condition always TRUE
>>> Warning 203 "main.c" Line 205(1,1): Condition always TRUE
>>> Warning 208 "main.c" Line 199(5,9): Function not void and does not return a value MAIN
And 2 errors because of this lines :
Code: | P1 = *lcd_string;//put high 8bits on port 1
P1 = *(++lcd_string);//put low 8bits on port 1 |
Could you help me again to solve that? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Wed Aug 31, 2011 4:37 am |
|
|
Code: |
void delay(unsigned int n) //Delay subroutine
{
unsigned int i,j;
for (i=0;i<n;i++)
for (j=0;j<350;j++)
{;}
}
|
The first error is here. In CCS C ints are 8 bit and unsigned by default. So, i and j can hold values from 0 to 255. 350 is more than an unsigned int can hold in CCS C, that's why the condition, j < 350;, is always true as it cannot ever be above 255, let alone 350. The same goes for any ints. This explains most of the warnings. To count to greater than 255 use int16 rather than int.
The final warning tell you that CCS C expects main() not to return any result, i.e. it should be declared as void Main(void).
Also this code may optimise away as it does "nothing", it merely counts. To give delays in CCS C use delay_us(n), delay_ms(n) or delay_cycles(n).
You should use the function output_X(value), where you should replace the X with the port you are actually using. You haven't actually defined what P1 is yet, and that is why you are getting the error.
All this is pretty basic CCS C and if you don't know this stuff then you really need to read the manual carefully! Certainly you cannot expect to get such an interface to hardware going properly unless you understand both the hardware and the firmware environment reasonably well.
RF Developer |
|
|
Alison
Joined: 30 Aug 2011 Posts: 5 Location: France
|
|
Posted: Thu Sep 01, 2011 8:21 am |
|
|
I don't understand why but the program doesn't work correctly. The brightness change for each of this lines :
Code: | displayQuads(); //color quadrants
Fulldisplay(0xF8,0x00); //Red
Fulldisplay(0x07,0xE0); //Green
Fulldisplay(0x00,0x1F); //Blue
Fulldisplay(0xFF,0xFF); //White
Fulldisplay(0x00,0x00); //Black
|
But there is none colour and no picture on the TFT.
http://mitchhodges.webs.com/Usingatft.html
Code: | #include <16F887.h>
#FUSES HS,NOWDT, NOPROTECT
#use delay (clock=8000000)
#define CS PIN_A0 //Chip select
#define RS PIN_A1 //Data/Instruction Register select
#define WR1 PIN_A2 //Write
#define RD1 PIN_A3 //Read
#define RESET PIN_A4 //Reset
#include <picture.h>
/*****************************************************/
void delay(unsigned int n) //Delay subroutine
{
unsigned int16 i,j;
for (i=0;i<n;i++)
for (j=0;j<350;j++)
{;}
}
/*****************************************************/
void data_out(unsigned char i) //Data Output 8-bit Bus Interface
{
output_high(RS); //Data register
output_high(RD1); //Read disable
output_low(WR1); //Write enable
output_B(i); //put byte on port 1
//nop
output_high(WR1); //Clock in data
}
void comm_out(unsigned char j) //Command Output 8-bit Bus Interface
{
output_low(RS); //Instruction register
output_high(RD1); //Read disable
output_low(WR1); //Write enable
output_B(j); //put byte on port 1
//nop
output_high(WR1); //Clock in data
}
/*****************************************************/
void Fulldisplay(unsigned char d1,unsigned char d2)//Fill display with RGB color
{
int i,j;
output_high(RS); //Data register
for(i=0;i<160;i++) //160 lines
{
for(j=0;j<128;j++) //128pixels/line
{
output_B(d1); //high 8bits
output_low(WR1);
//nop
output_high(WR1); //clock in data
output_B(d2); //low 8 bits
output_low(WR1);
//nop
output_high(WR1); //clock in data
}
}
}
/*****************************************************/
void dispPic(unsigned char *lcd_string) //show 16bpp bitmap, 128x107pixels
{
int16 i,j;
output_high(RS); //Data register
for(i=0;i<26;i++) //MAY REMOVE THIS LOOP - write 26 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
output_B(0x00);
output_low(WR1);
//nop
output_high(WR1);
}
}
for(i=0;i<107;i++) //MAY CHANGE TO i<160 - write 107 lines of picture data
{
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip first 56bytes
for(j=0;j<128;j++) //Write 128pixels/line
{
output_B(*lcd_string);//put high 8bits on port 1
output_low(WR1);
//nop
output_high(WR1); //Clock in data
output_B(*(++lcd_string));//put low 8bits on port 1
output_low(WR1);
//nop
output_high(WR1); //Clock in data
lcd_string++; //point to next byte of picture data
}
lcd_string += (112); //MAY REMOVE -
//my picture data is for 240pixels/line, skip last 56bytes also
}
for(i=0;i<27;i++) //MAY REMOVE THIS LOOP - write 27 lines of black pixels
{
for(j=0;j<256;j++) //256bytes = 128pixels/line
{
output_B(0x00);
output_low(WR1);
//nop
output_high(WR1);
}
}
}
/****************************************************/
void displayQuads() //split the display into quadrants of different colors
{
int i,j;
output_high(RS); //Data register
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
output_B(0x00);
output_low(WR1);
//nop
output_high(WR1);
output_B(0x1F); //0x00,0x1F = Blue
output_low(WR1);
//nop
output_high(WR1);
}
for(j=0;j<64;j++){ //64 pixels wide
output_B(0xF8);
output_low(WR1);
//nop
output_high(WR1);
output_B(0x00); //0xF8,0x00 = Red
output_low(WR1);
//nop
output_high(WR1);
}
}
for(i=0;i<80;i++){ //80 lines tall
for(j=0;j<64;j++){ //64 pixels wide
output_B(0xFF);
output_low(WR1);
//nop
output_high(WR1);
output_B(0xE0); //0xFF,0xE0 = Yellow
output_low(WR1);
//nop
output_high(WR1);
}
for(j=0;j<64;j++){ //64 pixels wide
output_B(0x07);
output_low(WR1);
//nop
output_high(WR1);
output_B(0xE0); //0x07,0xE0 = Green
output_low(WR1);
//nop
output_high(WR1);
}
}
}
/****************************************************
* Initialization For ILI9163 *
*****************************************************/
void resetLCD()
{
output_low(RESET);
delay_us(100); ////////////////////////////////////
output_high(RESET);
delay_ms(130); ///////////////////////////100
}
void init_LCD()
{
output_low(CS); //Chip Select = Active
comm_out(0x11); //exit sleep mode
delay_ms(100);
comm_out(0x26); data_out(0x04); //set gamma curve 3
comm_out(0xF2); data_out(0x00); //gamma adjustment enabled
comm_out(0xB1); data_out(0x0A); data_out(0x14); //frame rate
comm_out(0xC0); data_out(0x0A); data_out(0x00); //power control 1
comm_out(0xC1); data_out(0x02); //power control 2
comm_out(0xC5); data_out(0x2F); data_out(0x3E); //VCOM control 1
comm_out(0xC7); data_out(0x40); //VCOM offset control
comm_out(0x2A); //column address set
data_out(0x00);
data_out(0x00); //start column 0x0000
data_out(0x00);
data_out(0x7F); //end column 0x007F = 127
comm_out(0x2B); //page address set
data_out(0x00);
data_out(0x00); //start line 0x0000
data_out(0x00);
data_out(0x9F); //end line 0x009F = 159
comm_out(0x36); data_out(0xC0); //Memory access control
comm_out(0x3A); data_out(0xC5); //Pixel format = 16bit/pixel
comm_out(0x29); //display on
comm_out(0x2C); //write to frame memory(begin writing data)
}
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
/*****************************************************/
void main(void)
{
output_B(0x00);
resetLCD();
init_LCD();
while(1) //continue
{
displayQuads(); //color quadrants
delay_us(2000);
Fulldisplay(0xF8,0x00); //Red
delay_us(1500);
Fulldisplay(0x07,0xE0); //Green
delay_us(1500);
Fulldisplay(0x00,0x1F); //Blue
delay_us(1500);
Fulldisplay(0xFF,0xFF); //White
delay_us(1500);
Fulldisplay(0x00,0x00); //Black
delay_us(1500);
dispPic(picture); //16bpp bitmap
delay_us(2000);
}
} |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|