/**********************************************************************
*
* IDE : ATmanAVR(GCC)
* MCU : Atmeage8 @16MHz
* mail : Shushikuan
* ROM : 2414 bytes
* RAM : 460 bytes
* DATE : 2019-02-25
* FUNC : serial port to TV PAL
*
************************************************************************/
/***********************************************************************
*
* 1N4148 330 R
* | _______
* MOSI(PB3) |------|>------|_______|------
* | |
* | 1K |
* | 1N4148 _______ |
* OC1A(PB1) |------|>------|_______|------+--------------> PAL Output
* | |
* | |
* | -
* -------------- | |
* ATMega8 @16MHz | | 75 R
* | |
* |_|
* |
* |
* |
* -----
* ---
* -
*
************************************************************************/
#include "AVRTV.h"
#include <util/delay.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "font_8x16.h"
//AVRTV
// 38 2.375 uS
// 75 4.7uS
// 437 27.3uS
// 474 29.65 uS
// 512 32 uS
// 1024 64 uS
#define PW2350 37
#define PW4700 74
#define PW2730 436
#define PW2965 473
#define PW3200 511
#define PW6400 1023
#define CHAR_ROWS 13
#define CHAR_COLS 32
#define START_LINE 75
#define END_LINE 282 // START_LINE + CHAR_ROWS * 16 -1
#define FONT_HEIGHT 16
#define RECV_BUFF_SIZE 200
unsigned short scan_line = 1;
unsigned char char_buff[CHAR_ROWS][CHAR_COLS]; // 13 行 x 32 列个字符
unsigned char recv_buff[RECV_BUFF_SIZE];
unsigned char recv_len=0;
unsigned short text_cursor_pos =0;
// void ShowText(char row,char col,char * pStr)
// {
// unsigned char i=0,x,y;
// while(*pStr)
// {
// x=row+(col+i)/CHAR_COLS;
// y=(col+i) % CHAR_COLS;
// char_buff[x][y] = *pStr++;
// i++;
// }
//
// }
void ShowText(char row,char col,char * pStr)
{
unsigned char i=0,x,y;
unsigned char m,n;
while(*pStr)
{
if(*pStr==0x0D && *(pStr+1) == 0x0A){
text_cursor_pos = (text_cursor_pos /CHAR_COLS+1)*CHAR_COLS;
break;
}else{
x=row+(col+i)/CHAR_COLS;
y=(col+i) % CHAR_COLS;
char_buff[x][y] = *pStr++;i++;
text_cursor_pos = row * CHAR_COLS + y+1;
if(text_cursor_pos>= CHAR_ROWS * CHAR_COLS )
{
for(m=1;m<CHAR_ROWS;m++)
for(n=0;n<CHAR_COLS;n++)
char_buff[m-1][n] = char_buff[m][n];
for(n=0;n<CHAR_COLS;n++)
char_buff[m][n] = 32;
text_cursor_pos = (CHAR_ROWS-1) * CHAR_COLS;
}
}
}
}
void PutText(unsigned char * buff,short len)
{
short i,m,n,x,y;
for(i=0;i<len;i++)
{
if(buff[i]==0x0D && buff[i+1] == 0x0A){
text_cursor_pos = (text_cursor_pos /CHAR_COLS+1)*CHAR_COLS;
break;
}else if(buff[i]>=32 && buff[i] <=126){
if(text_cursor_pos>= CHAR_ROWS * CHAR_COLS )
{
for(m=1;m<CHAR_ROWS;m++)for(n=0;n<CHAR_COLS;n++)char_buff[m-1][n] = char_buff[m][n];
for(n=0;n<CHAR_COLS;n++)char_buff[CHAR_ROWS-1][n] = 32;
text_cursor_pos = (CHAR_ROWS-1) * CHAR_COLS;
}
x = text_cursor_pos / CHAR_COLS;
y = text_cursor_pos % CHAR_COLS;
char_buff[x][y] = buff[i];
text_cursor_pos ++;
}
}
}
// 9600,n,8,1
void USART_Init(void)
{
//ubrr = fosc/(16*baud)-1;
//baud = fosc/(16 * (ubrr+1));
UBRRH = 0x00;
UBRRL = 103; //波特率9600 , 103 = 16000000 / (16*9600) -1
UCSRA = 0x00; //不使用倍速
UCSRB = 0x98; // 接收器与发送器使能,接收中断使能
UCSRC = 0x86; // 设置帧格式: 8 个数据位, 1个停止位
}
static void spi_init(void)
{
DDRB = 0x2E;
PORTB = 0x00;
SPCR=0X54; //SPI主机、高位在先、4分频、SPI模式1
SPSR |=0X01; //倍频
}
static void timer1_init(void)
{
// 16-bit timer.
// FastPWM with ICR1=TOP.
// Inverting PWM on OC1A
//
// ___________________ _ 1
// |____| | _
// ^ ^ 0
//Bottom OC1A ICR1
//CPU 20MHz
//使用定时器1 (16位) 工作在快速PWM模式。
//定时器1从0 计数到 ICR1中设定的值。
//定时器1中的值与OCR1A相等时 , OCR1A切换为高电平 ,定时器1溢出时,OCR1A引脚为低电平;
//WGM1 = 14 , 0b 1110
ICR1 = 511; // 511 --- 32 uS , 1023 --- 64 uS
TCNT1 = 0;
TIMSK |= 1<<OCIE1A;
//TIMSK |= 1<<TOIE1;
TCCR1A = ( ( 1 << COM1A1 ) | ( 1 << COM1A0 ) | ( 1 << WGM11 ) | ( 0 << WGM10 ) ) ;
TCCR1B = ( ( 1 << WGM13 ) | ( 1 << WGM12 ) | ( 1 << CS10 ) ) ;
}
void inline mydelay(void)
{
volatile unsigned short i,j;
for(i=0;i<50;i++)
for(j=0;j<100;j++);
}
int main(void)
{
unsigned char i,j;
unsigned rxlen=0;
DDRD = 0xFE;
PORTD =0x81;
for(i=0;i<CHAR_ROWS;i++)
for(j=0;j<CHAR_COLS;j++)char_buff[i][j]=32;
for(i=0;i<RECV_BUFF_SIZE;i++)recv_buff[i]=0;
ShowText(0,0," [ AVR PAL ] ");
ShowText(1,0," ");
ShowText(2,0,"Shushikuan@163.com");
ShowText(3,0,"2019-02-25\r\n");
USART_Init();
spi_init();
timer1_init();
sei();
while(1)
{
mydelay();
if(rxlen==recv_len && recv_len !=0)
{
PutText(recv_buff,recv_len);
for(i=0;i<RECV_BUFF_SIZE;i++)recv_buff[i]=0x00;
rxlen =0;
recv_len =0;
}else{
rxlen=recv_len;
}
}
}
ISR(SIG_UART_RECV)
{
recv_buff[recv_len++] = UDR;
if(recv_len>=RECV_BUFF_SIZE)recv_len =0;
}
// ////////////////////////////////////////////////////////////////////////////////////
// // 此中断函数产生PAL波形
// ////////////////////////////////////////////////////////////////////////////////////
// // 16-bit timer.
// // FastPWM with ICR1=TOP.
// // Inverting PWM on OC1A
// //
// // ___________________ _ 1
// // |____| | _
// // ^ ^ 0
// //Bottom OC1A ICR1
//
// //CPU 16MHz
// //使用定时器1 (16位) 工作在快速PWM模式。
// //定时器1从0 计数到 ICR1中设定的值。
// //定时器1中的值与OCR1A相等时 , OCR1A切换为高电平 ,定时器1溢出时,OCR1A引脚为低电平;
// //WGM1 = 14 , 0b 1110
//
// //因为PAL波形对时序要求十分严格
// //所以此中断函数语语句的执行顺序不要随意更改
ISR( TIMER1_COMPA_vect )
{
unsigned char row;
unsigned char col;
unsigned char line;
//volatile unsigned char temp;temp=0; //消耗CPU时间达到延时的目的
scan_line++;if(scan_line >= 320)scan_line=1;
if(scan_line >= 10 && scan_line <= 313){
ICR1 = PW6400; OCR1A = PW4700;
if(scan_line >= START_LINE && scan_line <= END_LINE)
{
row = (scan_line -START_LINE)/FONT_HEIGHT;
line = (scan_line -START_LINE)%FONT_HEIGHT;
_delay_us(2.5);
for (col = 0;col < CHAR_COLS;col++)
{
SPDR = pgm_read_byte(&font8x16[char_buff[row][col]-32][line]);
}
}
return;
}
if(scan_line == 314) {ICR1 = PW6400; OCR1A = PW2350; return;}
if(scan_line >= 5 && scan_line <= 8 ) {ICR1 = PW3200; OCR1A = PW2350; return;}
if(scan_line >= 315 && scan_line <= 318) {ICR1 = PW3200; OCR1A = PW2350; return;}
if(scan_line == 319) {ICR1 = PW3200; OCR1A = PW2730; return;}
if(scan_line >= 1 && scan_line <= 4) {ICR1 = PW3200; OCR1A = PW2730; return;}
if(scan_line == 9 ) {ICR1 = PW3200; OCR1A = PW4700; return;}
}
没有合适的资源?快使用搜索试试~ 我知道了~
TTL串口转PAL视频信号_ATmega8@16MHz.rar
共19个文件
h:5个
bmp:2个
elf:1个
需积分: 5 8 下载量 65 浏览量
2019-05-09
15:59:36
上传
评论 1
收藏 556KB RAR 举报
温馨提示
串口转PAL电视信号,实现串口数据英文字符输出到电视机上显示(AV接口),ATmega8@16MHz, 开发环境AtmanAVR(GCC)。包含源码、电路图、电视机显示结果图等。
资源推荐
资源详情
资源评论
收起资源包目录
串口转PAL视频信号_ATmega8@16MHz.rar (19个子文件)
AVRTV
AVRTV.c 7KB
Debug
AVRTV.eep 13B
AVRTV.o 11KB
AVRTV.elf 11KB
AVRTV.hex 9KB
proteus
sim.PWI 1KB
sim.DSN 83KB
Last Loaded sim.DBK 83KB
Version.v 116B
AVRTV.h 367B
font_8x8.h 5KB
iom8.h 11KB
font_8x16.h 9KB
AVRTV.opt 961B
AVRTV.apj 2KB
AVRTV实际运行电视机上显示效果.bmp 2.03MB
_delay_x.h 11KB
AVRTV原理图.bmp 2.04MB
AVRTV.aws 305B
共 19 条
- 1
资源评论
shushikuan
- 粉丝: 3
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功