Persistance of Vision (PoV), 即視覺暫留現象, 人眼在觀察景物時,光信號傳人大腦神經,需經過一段短暫的時間,光的作用結束後,視覺形象並不立即消失,這種殘留的視覺稱“後像”,視覺的這一現象則被稱爲“視覺暫留”。其具體應用是電影的拍攝和放映。原因是由視神經的反應速度造成的.其時值是二十四分之一秒。是動畫、電影等視覺媒體形成和傳播的根據。
利用PoV,還可以製作電子小玩意,比如利用幾個LED,就能顯示圖案,字符等。
下面是一個利用PoV顯示時鐘的例子:
下面是一段利用PoV顯示字符的PIC單片機程序,利用CCS C編譯器編譯:
主程序文件: pov.c
#include "font.h"
#include "font.c"
#fuses HS,NOWDT,NOPROTECT,NOLVP /* DONNOT use WDT */
/* Port D drives the LEDs */
#use fast_io(D)
#use delay(clock = 4000000) /* the crystal frequency is 4.000 MHz*/
void display_string(int8 *str)
{
int8 font_matrix_buf[FONT_WIDTH];
int8 i, j;
for(i = 0; str[i] != 0; i++)
{
get_font_matrix(str[i], font_matrix_buf);
for(j = 0; j < FONT_WIDTH; j++)
{
output_d(font_matrix_buf[j]); /* output the dots */
delay_ms(5); /* delay some time */
}
output_d(0x00);
delay_ms(5);
}
}
/**********************************************************
Description:
The entry point of the whole program.
Parameters:
None.
Return Value:
None.
Note:
N/A.
Date:
2006-04-02
**********************************************************/
void main(void)
{
int8 string[]= {'C', 'h', 'i', 'n', 'a', 0x00};
set_tris_d(0x00); /* set portD to output mode */
while(1)
{
display_string(string);
delay_ms(200);
}
}
字模頭文件: font.h
#define FONT_H
#define FONT_WIDTH 5
/*
CCS C doesn't support double-byte array subscript. so we must put the font table
in different arrays.
*/
#define FONT_BLANK_TABLE_SIZE (1 * FONT_WIDTH)
#define FONT_NUMBER_TABLE_SIZE (10 * FONT_WIDTH)
#define FONT_UPPER_CASE_TABLE_SIZE (26 * FONT_WIDTH)
#define FONT_LOWER_CASE_TABLE_SIZE (26 * FONT_WIDTH)
void get_font_matrix(int8 ascii_code, int8 *buf);
#endif
字模c文件: font.c
*8*8ASC碼字模頭文件
*右轉90度ASC字模
*Modify:2005-3-16 14:31
********************************************************************/
const int8 font_blank_table[FONT_BLANK_TABLE_SIZE] = {
0x00,0x00,0x00,0x00,0x00// blank
};
const int8 font_number_table[FONT_NUMBER_TABLE_SIZE] = {
0x7C,0xA2,0x92,0x8A,0x7C,// 0
0x00,0x84,0xFE,0x80,0x00,// 1
0xC4,0xA2,0x92,0x8A,0x84,// 2
0x42,0x82,0x8A,0x96,0x62,// 3
0x30,0x28,0x24,0xFE,0x20,// 4
0x4E,0x8A,0x8A,0x8A,0x72,// 5
0x78,0x94,0x92,0x92,0x60,// 6
0x02,0xE2,0x12,0x0A,0x06,// 7
0x6C,0x92,0x92,0x92,0x6C,// 8
0x0C,0x92,0x92,0x52,0x3C// 9
};
const int8 font_uletter_table[FONT_UPPER_CASE_TABLE_SIZE] = {
0xFC,0x22,0x22,0x22,0xFC,// A
0xFE,0x92,0x92,0x92,0x6C,// B
0x7C,0x82,0x82,0x82,0x44,// C
0xFE,0x82,0x82,0x44,0x38,// D
0xFE,0x92,0x92,0x92,0x82,// E
0xFE,0x12,0x12,0x12,0x02,// F
0x7C,0x82,0x92,0x92,0x74,// G
0xFE,0x10,0x10,0x10,0xFE,// H
0x00,0x82,0xFE,0x82,0x00,// I
0x40,0x80,0x82,0x7E,0x02,// J
0xFE,0x10,0x28,0x44,0x82,// K
0xFE,0x80,0x80,0x80,0x80,// L
0xFE,0x04,0x18,0x04,0xFE,// M
0xFE,0x08,0x10,0x20,0xFE,// N
0x7C,0x82,0x82,0x82,0x7C,// O
0xFE,0x12,0x12,0x12,0x0C,// P
0x7C,0x82,0xA2,0x42,0xBC,// Q
0xFE,0x12,0x32,0x52,0x8C,// R
0x4C,0x92,0x92,0x92,0x64,// S
0x02,0x02,0xFE,0x02,0x02,// T
0x7E,0x80,0x80,0x80,0x7E,// U
0x3E,0x40,0x80,0x40,0x3E,// V
0x7E,0x80,0x70,0x80,0x7E,// W
0xC6,0x28,0x10,0x28,0xC6,// X
0x0E,0x10,0xE0,0x10,0x0E,// Y
0xC2,0xA2,0x92,0x8A,0x86// Z
};
const int8 font_lletter_table[FONT_LOWER_CASE_TABLE_SIZE] = {
0x40,0xA8,0xA8,0xA8,0xF0,// a
0xFE,0x88,0x88,0x88,0x70,// b
0x70,0x88,0x88,0x88,0x88,// c
0x70,0x88,0x88,0x88,0xFE,// d
0x70,0xA8,0xA8,0xA8,0x10,// e
0x08,0x08,0xFC,0x0A,0x0A,// f
0x10,0xA8,0xA8,0xA8,0x78,// g
0xFE,0x10,0x08,0x08,0xF0,// h
0x00,0x88,0xFA,0x80,0x00,// i
0x40,0x80,0x88,0x7A,0x00,// j
0xFE,0x20,0x50,0x88,0x00,// k
0x00,0x82,0xFE,0x80,0x00,// l
0xF8,0x08,0xF8,0x08,0xF0,// m
0xF8,0x10,0x08,0x08,0xF0,// n
0x70,0x88,0x88,0x88,0x70,// o
0xF8,0x28,0x28,0x28,0x10,// p
0x10,0x28,0x28,0x28,0xF8,// q
0xF8,0x10,0x08,0x08,0x00,// r
0x90,0xA8,0xA8,0xA8,0x48,// s
0x08,0x08,0x7E,0x88,0x88,// t
0x78,0x80,0x80,0x40,0xF8,// u
0x38,0x40,0x80,0x40,0x38,// v
0x78,0x80,0x60,0x80,0x78,// w
0x88,0x50,0x20,0x50,0x88,// x
0x18,0xA0,0xA0,0xA0,0x78,// y
0x88,0xC8,0xA8,0x98,0x88// z
};
void get_font_matrix(int8 ascii_code, int8 *buf)
{
int8 i;
int8 base;
if(ascii_code == ' ')
{
for(i=0, base=0; i < FONT_WIDTH; i++)
{
*(buf+i) = font_blank_table[base + i];
}
}
else if(ascii_code >= '0' && ascii_code <= '9')
{
for(i=0, base = (ascii_code - '0') * FONT_WIDTH; i < FONT_WIDTH; i++)
{
*(buf+i) = font_number_table[base + i];
}
}
else if(ascii_code >= 'A' && ascii_code <= 'Z')
{
for(i=0, base = (ascii_code - 'A') * FONT_WIDTH; i < FONT_WIDTH; i++)
{
*(buf+i) = font_uletter_table[base + i];
}
}
else
{
for(i=0, base = (ascii_code - 'a') * FONT_WIDTH; i < FONT_WIDTH; i++)
{
*(buf+i) = font_uletter_table[base + i];
}
}
}
這段程序會在PIC單片機的Port D點亮一排LED,用手晃動這排LED,就會看到“china”字樣。