fr0stb0iz
Joined: 29 Sep 2009 Posts: 13
|
Displaying a waveform on LCD- nokia6610 screen. |
Posted: Fri Oct 02, 2009 1:27 am |
|
|
Hi all, I want to display the output of the A2D conversion in a waveform on my LCD screen, but I got no idea how it can be done. Can anybody give me any ideas or tips ?
Is it possible for me to use the lcd_putc(result); function ?
My code is as follow,
Code: | #include <18F4520.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES H4 //Crystal Osc (<= 4mhz)
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //Don't Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=40000000)
#define LCD_RESET PIN_C0
#define LCD_CS PIN_C1
#define SPI_CLK PIN_C3
#define SPI_DI PIN_C4 //unused
#define SPI_DO PIN_C5
//#bit SSPEN = 0x14.5 // bit to turn on/off hardware SPI
#bit SSPEN = 0xFC6.5
// Epson S1D15G10 Command Set
#include <bmp.h>
#define DISON 0xaf
#define DISOFF 0xae
#define DISNOR 0xa6
#define DISINV 0xa7
#define SLPIN 0x95
#define SLPOUT 0x94
#define COMSCN 0xbb
#define DISCTL 0xca
#define PASET 0x75 // 00,131
#define CASET 0x15 // 00,131
#define DATCTL 0xbc
#define RGBSET8 0xce
#define RAMWR 0x5c
#define RAMRD 0x5d
#define PTLIN 0xa8
#define PTLOUT 0xa9
#define RMWIN 0xe0
#define RMWOUT 0xee
#define ASCSET 0xaa
#define SCSTART 0xab
#define OSCON 0xd1
#define OSCOFF 0xd2
#define PWRCTR 0x20
#define VOLCTR 0x81
#define VOLUP 0xd6
#define VOLDOWN 0xd7
#define TMPGRD 0x82
#define EPCTIN 0xcd
#define EPCOUT 0xcc
#define EPMWR 0xfc
#define EPMRD 0xfd
#define EPSRRD1 0x7c
#define EPSRRD2 0x7d
#define NOP 0x25
#define ENDPAGE 131
#define ENDCOL 131
//a few basic colors
#define RED 0xE0 // Color Code
#define GREEN 0x1C
#define BLUE 0x03
#define YELLOW 0xFC
#define MAGENTA 0xE3
#define CYAN 0x1F
#define BLACK 0x00
#define WHITE 0xFF
#include <lcd.c>
//// START OF MAIN .C SOURCE FILE ////
//#include "<path to .h file cut from above>"
#use fast_io(C)
/*****************************/
/* Table Font Size 5x7 Pixel */
/*****************************/
const unsigned char font[475] =
{
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // Sp
0x00 , 0x06 , 0x5F , 0x06 , 0x00 , // !
0x07 , 0x03 , 0x00 , 0x07 , 0x03 , // ,
0x24 , 0x7E , 0x24 , 0x7E , 0x24 , // #
0x24 , 0x2B , 0x6A , 0x12 , 0x00 , // $
0x63 , 0x13 , 0x08 , 0x64 , 0x63 , // %
0x36 , 0x49 , 0x56 , 0x20 , 0x50 , // &
0x00 , 0x07 , 0x03 , 0x00 , 0x00 , // //
0x00 , 0x3E , 0x41 , 0x00 , 0x00 , // (
0x00 , 0x41 , 0x3E , 0x00 , 0x00 , // )
0x08 , 0x3E , 0x1C , 0x3E , 0x08 , // *
0x08 , 0x08 , 0x3E , 0x08 , 0x08 , // +
0x00 , 0xE0 , 0x60 , 0x00 , 0x00 , // ,
0x08 , 0x08 , 0x08 , 0x08 , 0x08 , // -
0x00 , 0x60 , 0x60 , 0x00 , 0x00 , // .
0x20 , 0x10 , 0x08 , 0x04 , 0x02 , // /
0x3E , 0x51 , 0x49 , 0x45 , 0x3E , // 0
0x00 , 0x42 , 0x7F , 0x40 , 0x00 , // 1
0x62 , 0x51 , 0x49 , 0x49 , 0x46 , // 2
0x22 , 0x49 , 0x49 , 0x49 , 0x36 , // 3
0x18 , 0x14 , 0x12 , 0x7F , 0x10 , // 4
0x2F , 0x49 , 0x49 , 0x49 , 0x31 , // 5
0x3C , 0x4A , 0x49 , 0x49 , 0x30 , // 6
0x01 , 0x71 , 0x09 , 0x05 , 0x03 , // 7
0x36 , 0x49 , 0x49 , 0x49 , 0x36 , // 8
0x06 , 0x49 , 0x49 , 0x29 , 0x1E , // 9
0x00 , 0x6C , 0x6C , 0x00 , 0x00 , // :
0x00 , 0xEC , 0x6C , 0x00 , 0x00 , // ;
0x08 , 0x14 , 0x22 , 0x41 , 0x00 , // <
0x24 , 0x24 , 0x24 , 0x24 , 0x24 , // =
0x00 , 0x41 , 0x22 , 0x14 , 0x08 , // >
0x02 , 0x01 , 0x59 , 0x09 , 0x06 , // ?
0x3E , 0x41 , 0x5D , 0x55 , 0x1E , // @
0x7E , 0x09 , 0x09 , 0x09 , 0x7E , // A
0x7F , 0x49 , 0x49 , 0x49 , 0x36 , // B
0x3E , 0x41 , 0x41 , 0x41 , 0x22 , // C
0x7F , 0x41 , 0x41 , 0x41 , 0x3E , // D
0x7F , 0x49 , 0x49 , 0x49 , 0x41 , // E
0x7F , 0x09 , 0x09 , 0x09 , 0x01 , // F
0x3E , 0x41 , 0x49 , 0x49 , 0x7A , // G
0x7F , 0x08 , 0x08 , 0x08 , 0x7F , // H
0x00 , 0x41 , 0x7F , 0x41 , 0x00 , // I
0x30 , 0x40 , 0x40 , 0x40 , 0x3F , // J
0x7F , 0x08 , 0x14 , 0x22 , 0x41 , // K
0x7F , 0x40 , 0x40 , 0x40 , 0x40 , // L
0x7F , 0x02 , 0x04 , 0x02 , 0x7F , // M
0x7F , 0x02 , 0x04 , 0x08 , 0x7F , // N
0x3E , 0x41 , 0x41 , 0x41 , 0x3E , // O
0x7F , 0x09 , 0x09 , 0x09 , 0x06 , // P
0x3E , 0x41 , 0x51 , 0x21 , 0x5E , // Q
0x7F , 0x09 , 0x09 , 0x19 , 0x66 , // R
0x26 , 0x49 , 0x49 , 0x49 , 0x32 , // S
0x01 , 0x01 , 0x7F , 0x01 , 0x01 , // T
0x3F , 0x40 , 0x40 , 0x40 , 0x3F , // U
0x1F , 0x20 , 0x40 , 0x20 , 0x1F , // V
0x3F , 0x40 , 0x3C , 0x40 , 0x3F , // W
0x63 , 0x14 , 0x08 , 0x14 , 0x63 , // X
0x07 , 0x08 , 0x70 , 0x08 , 0x07 , // Y
0x71 , 0x49 , 0x45 , 0x43 , 0x00 , // Z
0x00 , 0x7F , 0x41 , 0x41 , 0x00 , // [
0x02 , 0x04 , 0x08 , 0x10 , 0x20 , // Back slash
0x00 , 0x41 , 0x41 , 0x7F , 0x00 , // ]
0x04 , 0x02 , 0x01 , 0x02 , 0x04 , // ^
0x80 , 0x80 , 0x80 , 0x80 , 0x80 , // _
0x00 , 0x03 , 0x07 , 0x00 , 0x00 , // `
0x20 , 0x54 , 0x54 , 0x54 , 0x78 , // a
0x7F , 0x44 , 0x44 , 0x44 , 0x38 , // b
0x38 , 0x44 , 0x44 , 0x44 , 0x28 , // c
0x38 , 0x44 , 0x44 , 0x44 , 0x7F , // d
0x38 , 0x54 , 0x54 , 0x54 , 0x18 , // e
0x08 , 0x7E , 0x09 , 0x09 , 0x00 , // f
0x18 , 0xA4 , 0xA4 , 0xA4 , 0x7C , // g
0x7F , 0x04 , 0x04 , 0x78 , 0x00 , // h
0x00 , 0x00 , 0x7D , 0x00 , 0x00 , // i
0x40 , 0x80 , 0x84 , 0x7D , 0x00 , // j
0x7F , 0x10 , 0x28 , 0x44 , 0x00 , // k
0x00 , 0x00 , 0x7F , 0x40 , 0x00 , // l
0x7C , 0x04 , 0x18 , 0x04 , 0x78 , // m
0x7C , 0x04 , 0x04 , 0x78 , 0x00 , // n
0x38 , 0x44 , 0x44 , 0x44 , 0x38 , // o
0xFC , 0x44 , 0x44 , 0x44 , 0x38 , // p
0x38 , 0x44 , 0x44 , 0x44 , 0xFC , // q
0x44 , 0x78 , 0x44 , 0x04 , 0x08 , // r
0x08 , 0x54 , 0x54 , 0x54 , 0x20 , // s
0x04 , 0x3E , 0x44 , 0x24 , 0x00 , // t
0x3C , 0x40 , 0x20 , 0x7C , 0x00 , // u
0x1C , 0x20 , 0x40 , 0x20 , 0x1C , // v
0x3C , 0x60 , 0x30 , 0x60 , 0x3C , // w
0x6C , 0x10 , 0x10 , 0x6C , 0x00 , // x
0x9C , 0xA0 , 0x60 , 0x3C , 0x00 , // y
0x64 , 0x54 , 0x54 , 0x4C , 0x00 , // z
0x08 , 0x3E , 0x41 , 0x41 , 0x00 , // {
0x00 , 0x00 , 0x7F , 0x00 , 0x00 , // |
0x00 , 0x41 , 0x41 , 0x3E , 0x08 , // }
0x02 , 0x01 , 0x02 , 0x01 , 0x00 // ~
};
void pset(unsigned char color, unsigned char x, unsigned char y);
void spi_command(int);
void spi_data(int);
void LCD_Set_Box(unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2);
void LCD_Plot_Graph(unsigned char color,
unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2);
void LCD_Draw_Line(unsigned char color,
unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2);
void LCD_Fill_Screen(unsigned char color,
unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2);
void LCD_Initial(void);
void Draw_Line_Bar(void);
void main()
{
int16 i,index,result;
char String_Buff[30]; // String Array Buffer
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
//setup_comparator(NC_NC_NC_NC);
delay_us(15);
// while(1)
//{
// result = read_adc();
// output_d(result);
// //delay_ms(50);
//}
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
// setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_XMIT_L_TO_H);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED, 0, 1);
set_tris_c(0x00); // all outputs, can change to mask only hardware SPI bits if needed
LCD_Initial();
while(1)
{
result = read_adc();
output_d(result);
lcd_putc(result);
//delay_ms(50);
LCD_Fill_Screen(RED,0,0,131,131);
delay_ms(500);
LCD_Fill_Screen(BLACK,0,0,131,131);
delay_ms(2000);
//GRAPH
LCD_Plot_Graph(RED,50,50,100,100);
delay_ms(2000);
LCD_Fill_Screen(BLACK,0,0,131,131);
delay_ms(1000);
//draw line
LCD_Draw_Line(RED,0,34,75,35);
delay_ms(1000);
delay_ms(2000);
spi_command(DATCTL); // datctl
spi_data(0x00);
spi_data(0);
spi_data(0x01);
spi_data(0);
}
}
void pset(unsigned char color, unsigned char x, unsigned char y){
// sets the starting page(row) and column (x & y) coordinates in ram,
// then writes the colour to display memory. The ending x & y are left
// maxed out so one can continue sending colour data bytes to the 'open'
// RAMWR command to fill further memory. issuing any other command
// finishes RAMWR.
x += 2; // for some reason starts at 2
spi_command(PASET); // page start/end ram
spi_data(x);
spi_data(ENDPAGE);
spi_command(CASET); // column start/end ram
spi_data(y);
spi_data(ENDCOL);
spi_command(RAMWR); // write
spi_data(color);
}
void spi_command(int dat){
output_low(LCD_CS); // enable chip
SSPEN = 0; // shut off hardware SPI allowing direct access to SPI in/out pins
output_low (SPI_DO); // output low on data out (9th bit low = command)
output_high (SPI_CLK);
delay_cycles(1); // send clock pulse
output_low (SPI_CLK);
SSPEN=1; // turn hardware SPI back on
spi_write(dat); // make PIC do the work for the command byte
output_high(LCD_CS); // disable
}
void spi_data(int dat){
output_low(LCD_CS); // enable chip
SSPEN = 0; // turn off hardware SPI allowing us direct access to SPI in/out pins
output_high (SPI_DO); // output high on data out (9th bit high = data)
output_high (SPI_CLK);
delay_cycles(1); // send clock pulse
output_low (SPI_CLK);
SSPEN=1; // turn hardware SPI back on
spi_write(dat); // make PIC do the work for the data byte
output_high(LCD_CS); // disable
}
/*************************/
/* Initial LCD-NOKIA6610 */
/*************************/
void LCD_Initial(void)
{
// reset display
output_low (SPI_CLK);
output_low (SPI_DO);
output_high (LCD_CS);
output_low (LCD_RESET);
delay_ms(100);
output_high (LCD_RESET);
//init'd, now drop CS to send commands/data and raise when finished
spi_command(DISCTL); // display control
spi_data(0x0C); // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default)
spi_data(0x20); // 32 = (128/4)-1 (round up) number of display lines for scanning
spi_data(0x0C); // 12 = 1100 - number of lines to be inversely highlighted
spi_data(0x00);
spi_command(COMSCN); // common scanning direction
spi_data(0x01);
// 0 0 0 = 1 -> 80 81 -> 160
// 0 0 1 = 1 -> 80 81 <- 160
// 0 1 0 = 1 <- 80 81 -> 160
// 0 1 1 = 1 <- 80 81 <- 160
spi_command(OSCON); // internal oscialltor ON
spi_command(SLPOUT); // sleep out
spi_command(VOLCTR); // electronic volume, this is the contrast/brightness
spi_data(0x23); // volume (contrast) setting - fine tuning
spi_data(0x03); // internal resistor ratio - coarse adjustment
spi_command(PWRCTR); // power ctrl
spi_data(0x0f); //everything on, no external reference resistors
delay_ms(100);
spi_command(DISINV); // invert display mode
spi_command(DATCTL); // data control
spi_data(0x00); // normal display of page/column address, page scan direction
spi_data(0x00); // normal RGB arrangement
spi_data(0x01); // 8-bit grayscale
spi_command(RGBSET8); // setup 8-bit color lookup table [RRRGGGBB]
//RED
spi_data(0);
spi_data(2);
spi_data(4);
spi_data(6);
spi_data(8);
spi_data(10);
spi_data(12);
spi_data(15);
// GREEN
spi_data(0);
spi_data(2);
spi_data(4);
spi_data(6);
spi_data(8);
spi_data(10);
spi_data(12);
spi_data(15);
//BLUE
spi_data(0);
spi_data(4);
spi_data(9);
spi_data(15);
spi_command(NOP); // nop
LCD_Fill_Screen(WHITE,0,0,131,131);
spi_command(DISON); // Display On
}
/********************************/
/* (x1,y1) */
/* ******************** */
/* * * */
/* * * */
/* ******************** */
/* (x2,y2) */
/********************************/
void LCD_Set_Box(unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2)
{
spi_command(CASET); // Page Start/Eend ram
spi_data(x1);
spi_data(x2);
spi_command(PASET); // Column Start/End ram
spi_data(y1);
spi_data(y2);
}
/**************************/
/* Fill Screen With Color */
/**************************/
void LCD_Fill_Screen(unsigned char color,
unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2)
{
unsigned int16 j;
unsigned int16 total_bytes1;
unsigned int16 total_bytes2;
unsigned int16 total_bytes;
LCD_Set_Box(x1, y1, x2, y2);
spi_command(RAMWR);
total_bytes1 = (x2 - x1 + 1);
total_bytes2 = (y2 - y1 + 1);
total_bytes = total_bytes1 * total_bytes2;
for (j = 0; j < total_bytes; j++)
{
spi_data(color);
}
}
/**********************/
/* Create line Bar Color */
/**********************/
void Draw_Line_Bar(void)
{
LCD_Draw_Line(RED,0,0,131,33);
}
/**************************/
/* draw line on Screen With Color */
/**************************/
void LCD_Draw_Line(unsigned char color,
unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2)
{
unsigned int16 k;
unsigned int16 total2_bytes1;
unsigned int16 total2_bytes2;
unsigned int16 total2_bytes;
LCD_Set_Box(x1, y1, x2, y2);
spi_command(RAMWR);
total2_bytes1 = (x2 - x1 + 1);
total2_bytes2 = (y2 - y1 + 1);
total2_bytes = total2_bytes1 * total2_bytes2;
for (k = 0; k < total2_bytes; k++)
{
spi_data(color);
}
}
/**************************/
/* Plotting Points */
/**************************/
void LCD_Plot_Graph(unsigned char color,
unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2)
{
unsigned int16 w;
unsigned int16 total3_bytes1;
unsigned int16 total3_bytes2;
unsigned int16 total3_bytes;
LCD_Set_Box(x1, y1, x2, y2);
spi_command(RAMWR);
total3_bytes1 = (x2 - x1 + 1);
total3_bytes2 = (y2 - y1 + 1);
total3_bytes = total3_bytes1 * total3_bytes2;
for (w= 0; w < total3_bytes; w++)
{
spi_data(color);
}
}
|
|
|