CCD软件使用及调试方法介绍
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1无法发现串口,用管理员身份运行上位机软件
2默认比特率111520
3电压后面跟的是ad值,是8位ad
4前瞻距离1.5左右
52中镜头对比
红色地
vcc
AD0
PA0 PA1
void StartIntegration(void) {
unsigned char i;
PORTA=0x02; /* SI = 1 */
SamplingDelay();
PORTA=0x03; /* CLK = 1 */
SamplingDelay();
PORTA=0x01; /* SI = 0 */
SamplingDelay();
PORTA=0x00; /* CLK = 0 */
for(i=0; i<127; i++) {
SamplingDelay();
SamplingDelay();
PORTA=0x01; /* CLK = 1 */
SamplingDelay();
SamplingDelay();
PORTA=0x00; /* CLK = 0 */
}
SamplingDelay();
SamplingDelay();
PORTA=0x01; /* CLK = 1 */
SamplingDelay();
SamplingDelay();
PORTA=0x00; /* CLK = 0 */
}
void ImageCapture(unsigned char * ImageData) {
unsigned char i;
unsigned char error;
unsigned int temp_int;
PORTA=0x02; /* SI = 1 */
SamplingDelay();
PORTA=0x03; /* CLK = 1 */
SamplingDelay();
PORTA=0x01; /* SI = 0 */
SamplingDelay();
//Delay 10us for sample the first pixel
for(i = 0; i < 10; i++) {
Cpu_Delay1us();
}
//Sampling Pixel 1
error = AO_Measure(TRUE);
error = AO_GetValue16(&temp_int);
*ImageData++ = (byte)(temp_int>>8);
PORTA=0x00; /* CLK = 0 */
for(i=0; i<127; i++) {
SamplingDelay();
SamplingDelay();
PORTA=0x01; /* CLK = 1 */
SamplingDelay();
SamplingDelay();
//Sampling Pixel 2~128
error = AO_Measure(TRUE);
error = AO_GetValue16(&temp_int);
*ImageData++ = (byte)(temp_int>>8);
PORTA=0x00; /* CLK = 0 */
}
SamplingDelay();
SamplingDelay();
PORTA=0x01; /* CLK = 1 */
SamplingDelay();
SamplingDelay();
PORTA=0x00; /* CLK = 0 */
}
SCI0CR2 |= ( 0x08 | 0x04 | 0x20);
AD
unsigned char OutFlg; /* Measurement finish flag */
unsigned ModeFlg;
void AO_Init(void)
{
OutFlg = 0; /* No measured value */
ModeFlg = 0; /* Device isn't running */
/* ATD0CTL4: SMP2=0,SMP1=0,SMP0=0,PRS4=0,PRS3=0,PRS2=0,PRS1=0,PRS0=1 */
ATD0CTL4 = 0x01U; /* Set sample time and prescaler */
/* ATD0CTL3: DJM=1,S8C=0,S4C=0,S2C=0,S1C=1,FIFO=0,FRZ1=0,FRZ0=0 */
ATD0CTL3 = 0x88U; /* Set ATD control register 3 */
/* ATD0CTL0: ??=0,??=0,??=0,??=0,WRAP3=1,WRAP2=1,WRAP1=1,WRAP0=1 */
ATD0CTL0 = 0x0FU; /* Set wrap around */
/* ATD0CTL1: ETRIGSEL=0,SRES1=0,SRES0=0,SMP_DIS=0,ETRIGCH3=1,ETRIGCH2=1,ETRIGCH1=1,ETRIGCH0=1 */
ATD0CTL1 = 0x0FU; /* Set resolution and discharge */
/* ATD0CTL2: ??=0,AFFC=1,ICLKSTP=0,ETRIGLE=0,ETRIGP=0,ET
RIGE=0,ASCIE=0,ACMPIE=0 */
ATD0CTL2 = 0x40U; /* Set ATD control register 2 */
}
void AO_MainMeasure(void)
{
if (ATD0STAT0_SCF) { /* Is a sequence completed? */
OutFlg = 1; /* Measured values are available */
ModeFlg = 0; /* Set the device to the stop mode */
}
}
byte AO_Measure(bool WaitForResult)
{
if (ModeFlg !=0) { /* Is the device in different mode than "stop"? */
return 0; /* If yes then error */
}
ModeFlg = 1; /* Set state of device to the measure mode */
OutFlg = 0; /* Output values aren't available */
/* ATD0CTL5: ??=0,SC=0,SCAN=0,MULT=0,CD=0,CC=0,CB=0,CA=0 */
ATD0CTL5 = 0x00U; /* Start conversions */
if (1) { /* Is WaitForResult TRUE? */
while (ModeFlg == 0) { /* Calling MainMeasure while IDLE state occured */
AO_MainMeasure(); /* A/D converter handler */
}
}
return 1; /* OK */
}
byte AO_GetValue16(word *Values)
{
if (ModeFlg != 0) { /* Is the device in any measure mode? */
AO_MainMeasure();
}
if (!OutFlg) { /* Is measured value(s) available? */
return 0; /* If no then error */
}
*Values = ((word)(ATD0DR0L)) << 8U; /* Save measured values to the output buffer */
return 1; /* OK */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 66 PIT0(void)
{
PITTF = 0x01U; /* Reset interrupt request flag */
TI_OnInterrupt(); /* Invoke user event */
}
#pragma CODE_SEG TI_CODE