注册会员
- 积分
- 111
- 威望
- 173
- 贡献
- 28
- 兑换币
- 0
- 注册时间
- 2011-1-20
- 在线时间
- 0 小时
|
是这个么?
#include <hidef.h> /* common defines and macros */
#include <mc9s12xs128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128b"
///////////////////////////////////////////////////////////////
//行同步中断输入捕捉1管脚.
//场同步中断IRQ
//Yn分别对应PORTMn
///////////////////////////////////////////////////////////////
#define SYNE_SETTING 3
#define REFDV_SEETTING 1 // PLLCLK =2*OSCCLK*(SYNR + 1)/(REFDV + 1) busclk=64M
#define delay {_asm nop;}
#define M 100
#define N 40
unsigned char buff[N][M];
byte Tclk_ready;
static byte cnt_HREF=0x01;
static int cnt=0x00;
static int p=0x00;
byte one_sample;
void delayms(int a)
{ int b;
byte i,j;
for(b=0;b<a;b++)
for(i=0;i<255;i++)
for(j=0;j<255;j++)
delay;delay;delay;
}
void init_CRG(byte para1,byte para2)
{
SYNR=para1;
REFDV=para2;
while(!CRGFLG_LOCK);
CLKSEL_PLLSEL=1;
}
void init_interupt()
{
IRQCR_IRQE=1; //下降沿触发
IRQCR_IRQEN=1; //场同步中断IRQ中断,初始化开启
TIOS=0x00; //行同步中断,外部输入捕捉0,1通道,初始化不开启
TCTL4=0x09; //通道0上升沿触发,通道1下降沿触发
TSCR2=0X01; //分频 (总线时间/2)
TSCR1=0x80;
TIE=0X00; //初始化定时器关闭
}
void init_port()
{
DDRB=0XFF;
PORTB=0Xaa;
DDRA=0X00;
PUCR=0x03;
// DDRT=0x00; //shu ru shezhi
}
void init_sys(byte p1,byte p2)
{
init_CRG(p1,p2);
init_interupt();
init_port();
}
/*-------串口初始化----------------------*/
void SciInit()
{
SCI0BDL = (unsigned char)((48000000UL /* OSC freq */ / 2) / 19200 /* baud rate */ / 16 /*factor*/);
SCI0CR1=0; /*normal,no parity*/
SCI0CR2=0X2C; /*RIE=1,TE=1,RE=1*/
}
/*-------发射端程序-----单字节发送-----------------*/
void SciTx(unsigned char text)
{
unsigned char temp;
temp=SCI0SR1; /*clear flag*/
while (!(SCI0SR1&0x80)); /* wait for output buffer empty */
SCI0DRH=0;
SCI0DRL=text;
}
/*---------接受部分------------------------*/
char SciRx(void){
char temp;
char result;
temp=SCI0SR1; /*clear flag*/
while(!(SCI0SR1&0x20));
result=SCI0DRL;
return result;
}
void TestXianshi(void)
{
byte i,j;
SciTx(0);
for(i=1;i<N;i++)
{
for(j=1;j<M;j++)
{
SciTx(j*3);
}
SciTx(0);
}
SciTx(0);
// SciTx(0);
}
void Send_piex(void)
{
byte i,j;
SciTx(0);
for(i=1;i<N;i++) //
{ //
for(j=0;j<M;j++)
{
if(buff[i][j]==0)
buff[i][j]=1;
SciTx(buff[i][j]);
// delayms();
}
SciTx(0);
}SciTx(0);
}
void main(void)
{
DisableInterrupts;
one_sample=1;
init_sys(SYNE_SETTING,REFDV_SEETTING);
SciInit();
EnableInterrupts;
// unsigned char aa[10]="123456789";
// SciTx('a');
// TestXianshi();
for(;;)
{
if(one_sample==2)
{
Send_piex();
one_sample=3;
IRQCR_IRQEN=1;
}
}
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 8 Port0_interrupt(void)
{ int i;
TIE=0X00;
TFLG1=0X01;
for(i=0;i<M;i++)
{
buff[cnt_HREF][i]=PORTA;
}
cnt_HREF++;
if(cnt_HREF<N)
{
p++;
if(p==5)
{
p=0X00;
TIE=0X01;
}
else
{
p++;
while(p>5)
{
p=1;
}
TIE=0X01;
}
}
else
{
TIE=0X00;
cnt_HREF=0;
one_sample=2;
}
}
#pragma CODE_SEG DEFAULT
/***************************场中断处理******************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED //场中断
void interrupt 6 IRQ_interrupt(void)
{
TIE=0X01; //开行中断 /////
IRQCR_IRQEN=0;
//关场中断使能
}
#pragma CODE_SEG DEFAULT
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 20 sci_interrupt(void)
{
unsigned char data;
DisableInterrupts;
data=SciRx();
EnableInterrupts;
}
#pragma CODE_SEG DEFAULT |
|