常驻嘉宾
- 积分
- 4437
- 威望
- 1708
- 贡献
- 987
- 兑换币
- 1119
- 注册时间
- 2013-9-20
- 在线时间
- 871 小时
|
为什么上位机显示不了采集数据 但能在串口助手上看 以下是程序 谁能帮我看看呀
1,主程序
#include "MCF52255.h"
#include "UART.h"
#include "ADC.h"
#include "PIT.h"
#include "CCD.h"
#include "GPIO.h"
unsigned char TimerFlag20ms = 0;
unsigned char Pixel[128];
unsigned char integration_piont;
unsigned char IntegrationTime = 10;
void delay(int xms) //xms毫秒延时
{
int ii,jj;
for(ii=0;ii<xms;ii++)
for(jj=0;jj<2000;jj++);
}
int main()
{ unsigned char send_data_cnt = 0;
GPIO_init();
uart0_init(80000000,115200);
ADC_init();
PIT0_init();
EnableInterrupts;
PIT0_start(5000);
while(1)
{
/* 20ms Task*/
if(TimerFlag20ms == 1)
{
TimerFlag20ms = 0;
/* Sampling CCD data */
ImageCapture(Pixel);
/* Calculate Integration Time */
CalculateIntegrationTime();
/* Send data to CCDView every 100ms **/
if(++send_data_cnt >= 5)
{
send_data_cnt = 0;
SendImageData(Pixel);
}
}
}
2,中断
}
include "PIT.h"
#include "CCD.h"
void PIT0_init()
{
MCF_PIT_PCSR(0)=MCF_PIT_PCSR_RLD//配置运行方式
|MCF_PIT_PCSR_PIF
|MCF_PIT_PCSR_PIE
|MCF_PIT_PCSR_OVW
|MCF_PIT_PCSR_PRE(9);//fPIT=fsys/2/2^PER
//at 80MHz
//0- 40000000Hz
//1- 20000000Hz
//2- 10000000Hz
//3- 5000000Hz
//4- 2500000Hz -0.4us
//5- 1250000Hz
//6- 625000Hz
//7- 312500Hz
//8- 156250Hz
//9- 78125Hz -12.8us
//10-39062.5Hz
//11-19531.25Hz
//12-9765.625Hz
//13-4882.8125Hz
//14-2441.40625Hz
//15-1220.703125Hz
//|MCF_PIT_PCSR_DBG;
//|MCF_PIT_PCSR_DOZE
MCF_PIT_PMR(0)=5000;//78125;
MCF_INTC0_IMRL&=~MCF_INTC_IMRL_MASKALL;
MCF_INTC0_IMRH&=~MCF_INTC_IMRH_INT_MASK55;//PIT0
MCF_INTC0_ICR55=MCF_INTC_ICR_IP(6)+MCF_INTC_ICR_IL(2);//PIT0
MCF_PIT_PCSR(0)|=MCF_PIT_PCSR_EN;
}
void PIT0_start(uint x)
{
MCF_PIT_PMR(0)=x;
// MCF_PIT_PCSR(0)|=MCF_PIT_PCSR_EN;
}
void PIT0_stop(void)
{
MCF_PIT_PCSR(0)&=~MCF_PIT_PCSR_EN;
}
__declspec(interrupt:0) void PIT0_handler(void)//interrupt source 55
{
MCF_PIT_PCSR(0)|=MCF_PIT_PCSR_PIF;//清除PIT标志位
TimerCnt20ms++;
/* 根据曝光时间计算20ms周期内的曝光点*/
integration_piont = 20 - IntegrationTime;
if(integration_piont >= 2)
{ /* 曝光点小于2(曝光时间大于18ms)则不进行再曝光 */
if(integration_piont == TimerCnt20ms)
StartIntegration(); /* 曝光开始 */
}
if(TimerCnt20ms >= 20)
{
TimerCnt20ms = 0;
TimerFlag20ms = 1;
}
}
3,CCD采集程序和上位机协议
#include "CCD.h"
#define TSL1401_CLK_1 MCF_GPIO_PORTUC = MCF_GPIO_PORTUC_PORTUC1
#define TSL1401_SI_1 MCF_GPIO_PORTUC = MCF_GPIO_PORTUC_PORTUC2
#define TSL1401_CLK_0 MCF_GPIO_PORTUC =~ MCF_GPIO_PORTUC_PORTUC1
#define TSL1401_SI_0 MCF_GPIO_PORTUC =~ MCF_GPIO_PORTUC_PORTUC2
/* 128个像素点的平均AD值 */
unsigned char PixelAverageValue;
/* 128个像素点的平均电压值的10倍 */
unsigned char PixelAverageVoltage;
/* 设定目标平均电压值,实际电压的10倍 */
int TargetPixelAverageVoltage = 30;
/* 设定目标平均电压值与实际值的偏差,实际电压的10倍 */
int PixelAverageVoltageError = 0;
/* 设定目标平均电压值允许的偏差,实际电压的10倍 */
int TargetPixelAverageVoltageAllowError = 2;
void CalculateIntegrationTime(void)
{
/* 计算128个像素点的平均AD值 */
PixelAverageValue = PixelAverage(128,Pixel);
/* 计算128个像素点的平均电压值,实际值的10倍 */
PixelAverageVoltage = (unsigned char)((int)PixelAverageValue * 25 / 128);
PixelAverageVoltageError = TargetPixelAverageVoltage - PixelAverageVoltage;
if(PixelAverageVoltageError < -TargetPixelAverageVoltageAllowError)
IntegrationTime--;
if(PixelAverageVoltageError > TargetPixelAverageVoltageAllowError)
IntegrationTime++;
if(IntegrationTime <= 1)
IntegrationTime = 1;
if(IntegrationTime >= 20)
IntegrationTime = 20;
}
unsigned char PixelAverage(unsigned char len, unsigned char *data)
{
unsigned char i;
unsigned int sum = 0;
for(i = 0; i<len; i++)
{
sum = sum + *data++;
}
return ((unsigned char)(sum/len));
}
void SendImageData(unsigned char * ImageData)
{
unsigned char i;
unsigned char crc = 0;
/* Send Data */
uart0_putchar('*');
uart0_putchar('L');
uart0_putchar('D');
SendHex(0);
SendHex(0);
SendHex(0);
SendHex(0);
for(i=0; i<128; i++)
{
SendHex(*ImageData++);
}
SendHex(crc);
uart0_putchar('#');
}
void StartIntegration(void)
{
unsigned char i;
TSL1401_SI_1; /* SI = 1 */
delay_200ns();
TSL1401_CLK_1; /* CLK = 1 */
delay_200ns();
TSL1401_SI_0; /* SI = 0 */
delay_200ns();
TSL1401_CLK_0; /* CLK = 0 */
for(i=0; i<127; i++)
{
delay_200ns();
delay_200ns();
TSL1401_CLK_1; /* CLK = 1 */
delay_200ns();
delay_200ns();
TSL1401_CLK_0; /* CLK = 0 */
}
delay_200ns();
delay_200ns();
TSL1401_CLK_1; /* CLK = 1 */
delay_200ns();
delay_200ns();
TSL1401_CLK_0; /* CLK = 0 */
}
void ImageCapture(unsigned char * ImageData)
{
unsigned char i;
TSL1401_SI_1; /* SI = 1 */
delay_200ns();
TSL1401_CLK_1; /* CLK = 1 */
delay_200ns();
TSL1401_SI_0; /* SI = 0 */
delay_200ns();
//Delay 10us for sample the first pixel
for(i = 0; i < 10; i++)
{
Cpu_Delay1us();
}
//Sampling Pixel 1
Pixel[0]=ADonce(1);
TSL1401_CLK_0; /* CLK = 0 */
for(i=0; i<127; i++)
{
delay_200ns();
delay_200ns();
TSL1401_CLK_1; /* CLK = 1 */
delay_200ns();
delay_200ns();
//Sampling Pixel 2~128
Pixel=ADonce(1);
TSL1401_CLK_0; /* CLK = 0 */
}
delay_200ns();
delay_200ns();
TSL1401_CLK_1; /* CLK = 1 */
delay_200ns();
delay_200ns();
TSL1401_CLK_0; /* CLK = 0 */
}
void SendHex(unsigned char hex)
{
unsigned char temp;
temp = hex >> 4;
if(temp < 10) {
uart0_putchar(temp + '0');
} else {
uart0_putchar(temp - 10 + 'A');
}
temp = hex & 0x0F;
if(temp < 10) {
uart0_putchar(temp + '0');
} else {
uart0_putchar(temp - 10 + 'A');
}
}
这是在串口上的显示 十六进制
文本显示
急求指导呀
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|