| View previous topic :: View next topic |
| Author |
Message |
Gedo
Joined: 11 Jun 2007 Posts: 2
|
Posted: Thu Jun 14, 2007 4:50 pm Post subject: flicked screen |
|
|
hi BRUNO.
i heve a problem .
im usung pic18F452 8mhz HS PLL . but dont get stable picture.
when run PIC i get your demo picture only in second . maybe vidoe signal is nat stable. when reset the circuit its replay and flicked .
my modified line:
and
| Code: | | PAL_picture(0, 0, logo_bmp, 128, 80) ; |
R9 and R8 resistor is for light end contrast
how to fix this problem?
thanx for all |
|
| Back to top |
|
Gedo
Joined: 11 Jun 2007 Posts: 2
|
Posted: Thu Jun 14, 2007 5:14 pm Post subject: |
|
|
Thanx Bruno ..
I'm fixed my Problem when i connect 1u cap power to gnd. now is stable.
and i see now your smail logo  |
|
| Back to top |
|
BrunoG Site Admin
Joined: 22 Nov 2005 Posts: 636
|
Posted: Thu Jun 14, 2007 6:03 pm Post subject: |
|
|
Hi Gedo, thanks, glad to know it works  _________________ BrunoG, Administrator |
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Wed Jul 11, 2007 1:59 pm Post subject: Simplest Video Card |
|
|
Hi, Bruno. Thanks for blink-demo.
Now i can start my simple video card...
I would like to use a matrix (char videoRAM[2][21][16]) as video memory
and a buffer (byte buf[25]) to get usart values from another pic.
buf[0]=>video page
buf[1]=>command
buf[2]=>rowindex
buf[3]=>colindex
buf[4..24]=> char data
So in the main loop i have to wait for usart ready and fill the buffer until max (24) or stop char(255)
if (Usart_Data_Ready()) {
buf[i] = Usart_Read();
}
when the buffer is full, i'll put the info in videoRAM.
So the drawscreen routine only get info from videoRAM and use putchar
Is it possible ?
2) i'd like to create char 3*5 char ( who can see them ????) can you please tell me how the char code are structured?
3)... sure next thing i'd like to use both my new char and standard char during char drawing... |
|
| Back to top |
|
BrunoG Site Admin
Joined: 22 Nov 2005 Posts: 636
|
Posted: Wed Jul 11, 2007 10:35 pm Post subject: |
|
|
1 : yes use PAL_fill(0) to clear the screen, then successive calls to PAL_char() to fill the screen with text
2 : fonts are defined in ROM with PAL_charTable, if you want to build a new font table of your own you will have to define a PAL_charTable2 for example, and rewrite PAL_char2(), PAL_write2()routines.
There is one line per char in PAL_charTable, the first line is character space (ascii 32), the first byte of the line is the first column char bitmap, then second column bitmap, and so on up to the 6th column.
3 : both fonts may be mixed, as long as you have enough ROM space to store font definition & associated routines  _________________ BrunoG, Administrator |
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Fri Jul 13, 2007 10:24 am Post subject: |
|
|
i'm trying to fill a 64 byte buffer from usart .
But after i send the first char it seems to go the free_buffer(); section .
Is this syntax correct ?
thanx
do {
if (Usart_Data_Ready()) { // If data is received
data_buffer = Usart_Read(); // Read the received data
if (ind_buffer<max_usart_buffer-1) {
array_buffer[ind_buffer]=data_buffer;
ind_buffer=ind_buffer+1;
}
else
{
data_buffer=254;
}
if (data_buffer=254) {
write_buffer();
free_buffer();
} ;
} //data in usart
} while (1);
drawscreen();
} //END |
|
| Back to top |
|
BrunoG Site Admin
Joined: 22 Nov 2005 Posts: 636
|
Posted: Fri Jul 13, 2007 11:32 pm Post subject: |
|
|
| Code: | | if (data_buffer=254) { |
try :
| Code: | | if (data_buffer == 254) { |
 _________________ BrunoG, Administrator |
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Sat Jul 14, 2007 1:37 pm Post subject: |
|
|
oh... damn...
well as you can see i usually don't use "C" as language... but BV, delphi, etc....
i'm so sorry... so let's go on...  |
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Mon Jul 16, 2007 1:25 pm Post subject: |
|
|
here is my code.
For debug purpose i use a key on portb to write "P" and #of line to video screen without using usart.
Is it correct the drawscrren funtion (that is called in the main loop) ?
I get info from video ram and put it on video using library routines.
Is it correct the usage of PAL_control ?
thankx !
| Code: |
* PicVideoCard
* By Merco. Library by BrunoG.
*/
#include "PAL_Library.h"
#include "pictures.h"
/*
* number of vertical pixels
* from 1 to 128 included
* the more pixels you have :
* - the less RAM you have
* - the less MCU time you have
*/
#define PAL_Y 128
#define max_usart_buffer 64 // #max byte from usart
#define max_video_rows 16 // #max video rows
#define max_video_cols 21 // #max video columns
#define stop_byte 255 // stop byte from usart
/********************
* RAM VARIABLES
********************/
/*
* screen memory map
* do not change this line !
*/
unsigned char PAL_screen[PAL_X * PAL_Y / 8] ;
unsigned short current_video_mode; // current video page
unsigned short ind_buffer; // current usart buffer index
unsigned short data_buffer; // current usart byte read
unsigned short array_buffer[max_usart_buffer]; // array read from usart
unsigned short debug_line;
// Video RAM variables
// Two pages (0..1)
// video_RAM => contains characters
// video_RAM_Att => contains attributes
unsigned short video_RAM[2][max_video_rows][max_video_cols];
unsigned short video_RAM_Att[2][max_video_rows][max_video_cols];
/*
* convert value v into string pointed to by p, leading zero blanks if blk is set
*/
void char2str(unsigned char *p, unsigned char v, unsigned char blk)
{
*p = v / 10 + '0' ;
if(blk && (*p == '0'))
{
*p = ' ' ;
}
p++ ;
*p = v % 10 + '0' ;
p++ ;
*p = 0 ;
}
/*
* draw screen
*/
void drawScreen()
{
unsigned short r;
unsigned short c;
unsigned short att;
PAL_control(PAL_CNTL_START, PAL_CNTL_RENDER) ;
for (r =0; r <max_video_rows; r++)
{
for (c =0; c <max_video_cols; c++)
{
ATT=video_RAM_Att[current_video_mode][r][c];
PAL_char( c,r, video_RAM[current_video_mode][r][c],att);
}
}
}
/*
* interrupt service routine
*/
void interrupt(void)
{
/*
* do PAL stuff
*/
PAL_ISR() ; // library call
}
/*
* delete video RAM (CLS)
* if currentvideo page then empty it
*/
void Free_Video_MEM(unsigned int VideoPage)
{
unsigned short r;
unsigned short c;
for (r =1; r <max_video_rows; r++)
{
for (c =1; c <max_video_cols; c++)
{
video_RAM[VideoPage][r][c]=0;
video_RAM_Att[VideoPage][r][c]=0;
}
}
if (current_video_mode==VideoPage)
{
PAL_fill(0) ;
}
}
/*
* set the current video page
*/
void Set_Video_Page(unsigned int VideoPage)
{
current_video_mode=VideoPage;
}
/*
* free the usart buffer
*/
void free_buffer(void)
{
for (ind_buffer =0; ind_buffer <max_usart_buffer; ind_buffer++)
{
array_buffer[ind_buffer]=stop_byte;
} ;
data_buffer=stop_byte;
ind_buffer=0;
}
/*
* write the content of the usart buffer
* to video memory.
buf[0]=>video page
buf[1]=>command
buf[2]=>attribute
buf[3]=>rowindex
buf[4]=>colindex
*/
void write_buffer(void)
{
unsigned short i;
unsigned short vp;
unsigned short cmd;
unsigned short att;
unsigned short row;
unsigned short col;
unsigned short x;
if (ind_buffer<5)
{
return;
}
cmd=stop_byte;
vp=array_buffer[0];
if (vp>2)
{
return;
}
cmd=array_buffer[1];
if (cmd>2)
{
return;
}
att=array_buffer[2];
if (att>35)
{
return;
}
row=array_buffer[3];
if (row>max_video_rows)
{
return;
}
col=array_buffer[4];
if (col>max_video_cols)
{
return;
}
/* usart_write('W');
usart_write(vp);
usart_write(cmd);
usart_write(att);
usart_write(row);
usart_write(col);
usart_write('|');*/
switch (cmd) {
case 1: Free_Video_MEM(vp); break;
case 2: Set_Video_Page(vp); break;
}
x=0;
for (i =5; i <(ind_buffer-1); i++)
{
x=x+1;
video_RAM[vp][row][col+x]=array_buffer[i];
// usart_write(array_buffer[i]);
video_RAM_Att[vp][row][col+x]=att;
} ;
}
void maindebug (void)
{
if(PORTB & 0b1111111) // a key is pressed
{
debug_line=debug_line+1;
if (debug_line>max_video_rows) {
debug_line=1 ;
};
array_buffer[0]=0 ;
array_buffer[1]=0;
array_buffer[2]=PAL_CHAR_STANDARD;
array_buffer[3]=debug_line;
array_buffer[4]=1 ;
array_buffer[5] =80; //P
array_buffer[6] = 48+debug_line;
array_buffer[7]=stop_byte ;
ind_buffer=8;
write_buffer();
free_buffer();
usart_write('D');
while(PORTB & 0b1111111) ; // wait for the key to be released
}
}
/*
* main program
*/
void main(void)
{
/*
* I/O configuration
*/
ADCON1 = 0x0f ;
TRISA = 0xff ;
PORTA = 0 ;
TRISB = 0xff ;
PORTB = 0 ;
TRISC = 0xff ;
PORTC = 0 ;
TRISD = 0 ;
PORTD = 0 ;
TRISE = 0 ;
PORTE = 0 ;
debug_line=0;
// Initialize USART module (8 bit, 9600 baud rate, no parity bit..)
Usart_Init(9600);
ind_buffer=0;
data_buffer=stop_byte;
current_video_mode=0;
free_buffer();
/*
* start video and display first screen
*/
PAL_init(PAL_Y) ; // init PAL library
PAL_fill(0) ; // clear screen
do {
if (Usart_Data_Ready()) { // If data is received
data_buffer = Usart_Read(); // Read the received data
if (ind_buffer<max_usart_buffer) {
array_buffer[ind_buffer]=data_buffer;
ind_buffer=ind_buffer+1;
}
else
{
data_buffer=stop_byte;
}
if (data_buffer==stop_byte) {
write_buffer();
free_buffer();
} ;
} //data in usart
maindebug();
drawscreen();
} while (1);
} //END
|
|
|
| Back to top |
|
BrunoG Site Admin
Joined: 22 Nov 2005 Posts: 636
|
Posted: Wed Jul 18, 2007 11:03 pm Post subject: |
|
|
I did not check your code, but why don't you print the characters on the fly ? clearing screen each time may blank the display for a while. _________________ BrunoG, Administrator |
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Thu Jul 19, 2007 7:18 am Post subject: |
|
|
on the fly ?
i suppose that a "videoram" could be better (i can use 2 pages)... |
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Thu Jul 19, 2007 10:05 pm Post subject: |
|
|
now i use only array_buffer to store byte reads from usart.
For debug purpose i fill it in this way.
| Code: |
array_buffer[0]=0 ;
array_buffer[1]=0;
array_buffer[2]=PAL_CHAR_STANDARD;
array_buffer[3]=debug_line;
array_buffer[4]=0 ;
array_buffer[5] =68; //D
array_buffer[6] =65; //A
array_buffer[7] = 86; //V
array_buffer[8] = 48+debug_line;
array_buffer[9]=stop_byte ;
ind_buffer=10;
buffer_pieno=1;
|
So i suppose to write at location 0,0 the word "DAV" and the value of line (0).
So my "drawscreen" call a function "writebuffer" that uses directly Pal library function in this way:
| Code: |
for (i =5; i <(ind_buffer-1); i++)
{
if (array_buffer[i] != 255)
{
carwr= array_buffer[i];
PAL_CHAR(row, col, carwr, att) ;
PAL_constWrite(row+1,col,"L", PAL_CHAR_STANDARD) ;
col=col+1;
};
} ;
|
A strange thing happens: the second right is corretcly filled with four "L" (LLLL) but in the first line i see only 1 charachet at location 0,0.
Could be conversion from char and array_buffer type ? i declared it as
| Code: |
unsigned short array_buffer[max_usart_buffer];
unsigned char carWr;
|
What do you think ?
Here is all the code:
| Code: |
/*
* see more details on http://www.micro-examples.com/
*/
#include "PAL_Library.h"
#include "pictures.h"
/*************
* DEFINITIONS
*************/
/*
*/
#define PAL_Y 128
#define max_usart_buffer 64 // #max byte from usart
#define max_video_rows 16 // #max video rows
#define max_video_cols 21 // #max video columns
#define stop_byte 255 // stop byte from usart
/********************
* RAM VARIABLES
********************/
/*
* screen memory map
* do not change this line !
*/
unsigned char PAL_screen[PAL_X * PAL_Y / 8] ;
unsigned short current_video_mode; // current video page
unsigned short ind_buffer; // current usart buffer index
unsigned short data_buffer; // current usart byte read
unsigned short array_buffer[max_usart_buffer]; // array read from usart
unsigned short debug_line;
unsigned short buffer_pieno;
// Video RAM variables
// Two pages (0..1)
// video_RAM => contains characters
// video_RAM_Att => contains attributes
unsigned short video_RAM[2][max_video_rows][max_video_cols];
unsigned short video_RAM_Att[2][max_video_rows][max_video_cols];
/*
* general purpose string
*/
unsigned char str[20] ;
unsigned long oldCtr = 0 ; // frame counter backup
/*************************
* FUNCTIONS
*************************/
/*
* adjust time struct member
*/
void adjust(unsigned char *v, unsigned char min, unsigned char max)
{
if(PORTB.F7)
{
if(*v == min) *v = max ;
else (*v)-- ;
}
else
{
if(*v == max) *v = min ;
else (*v)++ ;
}
}
/*
* convert value v into string pointed to by p, leading zero blanks if blk is set
*/
void char2str(unsigned char *p, unsigned char v, unsigned char blk)
{
*p = v / 10 + '0' ;
if(blk && (*p == '0'))
{
*p = ' ' ;
}
p++ ;
*p = v % 10 + '0' ;
p++ ;
*p = 0 ;
}
/*
* interrupt service routine
*/
void interrupt(void)
{
/*
* do PAL stuff
*/
PAL_ISR() ; // library call
}
/*
* main program
*/
/*
* delete video RAM (CLS)
* if currentvideo page then empty it
*/
void Free_Video_MEM(unsigned int VideoPage)
{
PAL_fill(0) ;
}
/*
* set the current video page
*/
void Set_Video_Page(unsigned int VideoPage)
{
current_video_mode=VideoPage;
}
/*
* free the usart buffer
*/
void free_buffer(void)
{
for (ind_buffer =0; ind_buffer <max_usart_buffer; ind_buffer++)
{
array_buffer[ind_buffer]=stop_byte;
} ;
data_buffer=stop_byte;
ind_buffer=0;
buffer_pieno=0;
}
/*
* write the content of the usart buffer
* to video memory.
buf[0]=>video page
buf[1]=>command
buf[2]=>attribute
buf[3]=>rowindex
buf[4]=>colindex
*/
void write_buffer(void)
{
unsigned short i;
unsigned short vp;
unsigned short cmd;
unsigned short att;
unsigned short row;
unsigned short col;
unsigned short x;
unsigned char carWr;
if (ind_buffer<5)
{
return;
}
cmd=stop_byte;
vp=array_buffer[0];
if (vp>2)
{
return;
}
cmd=array_buffer[1];
if (cmd>2)
{
return;
}
att=array_buffer[2];
if (att>35)
{
return;
}
row=array_buffer[3];
if (row>max_video_rows)
{
return;
}
col=array_buffer[4];
if (col>max_video_cols)
{
return;
}
switch (cmd) {
case 1: Free_Video_MEM(vp); break;
case 2: Set_Video_Page(vp); break;
}
for (i =5; i <(ind_buffer-1); i++)
{
if (array_buffer[i] != 255)
{
carwr= array_buffer[i];
PAL_CHAR(row, col, carwr, att) ;
PAL_constWrite(row+1,col,"L", PAL_CHAR_STANDARD) ;
col=col+1;
};
} ;
}
void maindebug (void)
{
if(PORTB & 0b1111111) // a key is pressed
{
debug_line=debug_line+1;
if (debug_line>max_video_rows) {
debug_line=1 ;
};
array_buffer[0]=0 ;
array_buffer[1]=0;
array_buffer[2]=PAL_CHAR_STANDARD;
array_buffer[3]=debug_line;
array_buffer[4]=1 ;
array_buffer[5] =80; //P
array_buffer[6] = 48+debug_line;
array_buffer[7]=stop_byte ;
ind_buffer=8;
write_buffer();
free_buffer();
}
}
void maindebug_2 (void)
{
debug_line=debug_line+1;
if (debug_line>max_video_rows) {
debug_line=1 ;
};
array_buffer[0]=0 ;
array_buffer[1]=0;
array_buffer[2]=PAL_CHAR_STANDARD;
array_buffer[3]=debug_line;
array_buffer[4]=0 ;
array_buffer[5] =68; //D
array_buffer[6] =65; //A
array_buffer[7] = 86; //V
array_buffer[8] = 48+debug_line;
array_buffer[9]=stop_byte ;
ind_buffer=10;
buffer_pieno=1;
//usart_write('D');
// while(PORTB & 0b1111111) ; // wait for the key to be released
}
/*
* draw screen with decoration if full is set, using video mode mode
*/
void drawScreen(unsigned char full, unsigned char mode)
{
unsigned short r;
unsigned short c;
unsigned short att;
unsigned short cara;
//PAL_fill(0) ;
PAL_control(PAL_CNTL_START, mode) ;
if(full) // draw full screen with decoration
{
PAL_fill(0) ;
/*for (r =0; r <max_video_rows; r++)
{
for (c =0; c <max_video_cols; c++)
{
cara=video_RAM[current_video_mode][r][c];
ATT=video_RAM_Att[current_video_mode][r][c];
if (cara!=0) {
PAL_char( c,r, cara,PAL_CHAR_STANDARD);
}
}
}*/
// usart_write('F');
PAL_constWrite(15, 0, "012345678901234567890", PAL_CHAR_STANDARD) ;
} ;
//if(PAL_frameCtr > OldCtr) // it's time to update the clock & calendar
// {
oldCtr = PAL_frameCtr + 24 ; // prepare oldCtr for next update time
if (buffer_pieno==1)
{
//usart_write('P');
write_buffer();
free_buffer();
};
//usart_write('S');
//PAL_constWrite(5,1,"a", PAL_CHAR_STANDARD);
//PAL_constWrite(1,5,"b", PAL_CHAR_STANDARD);
//PAL_constWrite(2,5,"c", PAL_CHAR_STANDARD) ;
PAL_control(PAL_CNTL_START, PAL_CNTL_RENDER) ; // restore video rendering if it was stopped
// }
}
void main(void)
{
unsigned char i ;
/*
* I/O configuration
*/
ADCON1 = 0x0f ;
TRISA = 0xff ;
PORTA = 0 ;
TRISB = 0xff ;
PORTB = 0 ;
TRISC = 0xff ;
PORTC = 0 ;
TRISD = 0 ;
PORTD = 0 ;
TRISE = 0 ;
PORTE = 0 ;
USART_INIT(9600);
ind_buffer=0;
data_buffer=stop_byte;
current_video_mode=0;
free_buffer();
debug_line=0;
/*
* start video and display first screen
*/
PAL_init(PAL_Y) ; // init PAL library
PAL_fill(0) ; // clear screen
PAL_control(PAL_CNTL_START, PAL_CNTL_RENDER) ; // start video and rendering
i = 0 ;
PAL_setBorder(PAL_COLOR_BLACK) ; // clear border
drawScreen(1, PAL_CNTL_BLANK) ; // draw full screen in blank mode (faster)
maindebug_2();
for(;;)
{
// wait for the key to be released
PAL_frameCtr = 0 ; // reset counters
oldCtr = 0 ;
//maindebug_2;
drawScreen(0, PAL_CNTL_RENDER) ; // update screen
}
}
|
|
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Fri Jul 20, 2007 8:22 pm Post subject: |
|
|
no....
i can't see my characters...
I see correctly "LLLL" but not the content of the array_buffer (DAV):
probably something at location 0,0 is written from buffer_array but a the chars are over each other, i suppose....
 |
|
| Back to top |
|
BrunoG Site Admin
Joined: 22 Nov 2005 Posts: 636
|
Posted: Fri Jul 20, 2007 9:16 pm Post subject: |
|
|
I will try to test your program this week end, stay tuned. _________________ BrunoG, Administrator |
|
| Back to top |
|
merco
Joined: 02 May 2007 Posts: 34
|
Posted: Sun Jul 22, 2007 10:57 am Post subject: |
|
|
pal_char still doesn't work...
Only if I put my buffer in a string and then i use palwrite... this works, but it's not a good way... Why pal_char is not working ?  |
|
| Back to top |
|
|
|
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
|