📄 main.c
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : main.c
* Author : wuyuhuai
* Date First Issued : 4/40/2008 : V1.0
* Description : str training demo main file
********************************************************************************
* History:
* 10/01/2006 : V1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "6301.h"
#include "usb_lib.h"
#include "hw_config.h"
#include "71x_lib.h"
#include "ccid.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Extern function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#include "usb_lib.h"
#include "hw_config.h"
#include "71x_lib.h"
#include "adc12.h"
#include "71x_map.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Extern function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
u8 CNT10,CNT1;
u8 counter;
extern u8 Bulk_Out_Data_Buff[BULK_MAX_PACKET_SIZE];
extern u8 Bulk_In_Data_Buff[BULK_MAX_PACKET_SIZE];
extern void Send_Data(u8* Data_Address,u16 Data_Length);
int FIFOData_Len=0;
extern u8 Card;
bool Flag_main;
u8 ADC10,ADC1;
u16 KeyInput;
u16 adc_filter_cnt;
u32 adcdata,adc_result;
#define SA 0x0002
#define SB 0x0004
#define SC 0x0008
#define SD 0x0010
#define SE 0x0020
#define SF 0x0040
#define SG 0x0080
#define SH 0x0100
#define Digit_0 SA | SB | SC | SD | SE | SF
#define Digit_1 SB | SC
#define Digit_2 SA | SB | SD | SE | SG
#define Digit_3 SA | SB | SC | SD | SG
#define Digit_4 SB | SC | SF | SG
#define Digit_5 SA | SC | SD | SF | SG
#define Digit_6 SA | SC | SD | SE | SF | SG
#define Digit_7 SA | SB | SC
#define Digit_8 SA | SB | SC | SD | SE | SF | SG
#define Digit_9 SA | SB | SC | SD | SF | SG
#define Digit_A SA | SB | SC | SE | SF | SG
#define Digit_B SC | SD | SE | SF | SG
#define Digit_C SA | SD | SE | SF
#define Digit_D SB | SC | SD | SE | SG
#define Digit_E SA | SD | SE | SF | SG
#define Digit_F SA | SE | SF | SG
#define Digit_SP 0
const u16 DigitTab[] = {Digit_0,Digit_1,Digit_2,Digit_3,
Digit_4,Digit_5,Digit_6,Digit_7,
Digit_8,Digit_9,Digit_A,Digit_B,
Digit_C,Digit_D,Digit_E,Digit_F,
Digit_SP};
void Set_EIC(void)
{
EIC_IRQChannelPriorityConfig(T0TIMI_IRQChannel,2);
EIC_IRQChannelConfig(T0TIMI_IRQChannel,ENABLE);
TIM_Init(TIM0);
TIM_PrescalerConfig(TIM0,0x07);
TIM_ITConfig(TIM0,TIM_TO_IT,ENABLE);
EIC_IRQConfig(ENABLE);
TIM_CounterConfig(TIM0,TIM_START);
}
void InitP0(void)
{
GPIO0->PC0 &= 0xFF03;
GPIO0->PC1 &= 0xFF03;
GPIO0->PC2 &= 0xFF03;
GPIO0->PC0 |= 0x00FC; // Set [P07:P02] as PP output, P07(COM2) & P06(COM1)
GPIO0->PC1 |= 0x0000; // [P05:P02] = [LD5:LD2]
GPIO0->PC2 |= 0x00FC;
GPIO0->PD &= 0xFF3F; // Init P07=0,P06=0, [P05:P02]=1
}
void InitP1(void)
{
GPIO1->PC0 &= 0x0000;
GPIO1->PC1 &= 0x0000;
GPIO1->PC2 &= 0x0000;
GPIO1->PC0 |= 0x01FE; // Set [P1.8:P1.2] as PP output
GPIO1->PC1 |= 0xFE00; // Set P1.10 and [P1.13:P1.15] as CMOS input
GPIO1->PC2 |= 0x01FE; // Set P1.0 as AIN
GPIO1->PD &= 0xFE01; // Init [P1.8:P1.2] =0 and [P1.15:P1.13,P1.10]=1
}
void InitLED(void)
{
InitP1();
InitP0();
}
void Display(u8 Digit,u8 position)
{
u16 i;
GPIO0->PD &= 0xFF3F;
Digit &= 0x0F;
GPIO1->PD = DigitTab[Digit];
if (position == 0)
GPIO0->PD |= 0x0080; // P07= COMM of digit 10
else
GPIO0->PD |= 0x0040; // P06= COMM of digit 1
for(i=0; i<0x100; i++);
}
void Init_tim1(void)
{
/* TIM1 configuration */
TIM1->CR2 = 0x2007; // Enable interrupt and prescale=7
TIM1->CR1 = 0x8000; // Enable counter
// TIM1->CNTR = 0xf000; // Any value written to this Reg results reset to FFFC
}
void InitIE(void)
{
EIC_IRQChannelPriorityConfig(T1TIMI_IRQChannel,2);
EIC_IRQChannelConfig(T1TIMI_IRQChannel,ENABLE);
TIM_Init(TIM1);
TIM_PrescalerConfig(TIM1,0x07);
TIM_ITConfig(TIM1,TIM_TO_IT,ENABLE);
EIC_IRQConfig(ENABLE);
TIM_CounterConfig(TIM1,TIM_START);
}
int main(void)
{
#ifdef DEBUG
debug();
#endif
u8 cTmp;
Set_USBClock();
USB_Interrupts_Config(); /*configure and enable the USB interrupt*/
USB_Init(); /* Initialize the USB micro cell */
counter = 0;
adc_filter_cnt= 0;
adcdata = 0;
//
// Set_Clock(); // set main and APB clock
InitLED();
InitIE();
/* Configure the EIC channel interrupt */
EIC_IRQChannelPriorityConfig(ADC_IRQChannel,1);
EIC_IRQChannelConfig(ADC_IRQChannel,ENABLE);
EIC_IRQConfig(ENABLE);
/* ADC12 peripheral configuration ----------------------------------------*/
/* Initialize the conveter register. */
ADC12_Init();
/* Configure the prescaler register using the configured PCLK with
a sampling frequency=80Hz */
ADC12_PrescalerConfig(80);
/* Select the conversion mode=single channel */
ADC12_ModeConfig (ADC12_SINGLE);
/* Select the channel to be converted */
ADC12_ChannelSelect(ADC12_CHANNEL0);
/* Enable the ADC12 intruupts */
ADC12_ITConfig (ENABLE);
/* Start the Converter */
ADC12_ConversionStart();
KeyInput = GPIO1->PD;
while(1)
{
while((KeyInput&0x0200)==0x0200)
{
Display(CNT10,0);
Display(CNT1,1);
KeyInput=GPIO1->PD;
}
while((KeyInput&0x0400)==0x0400)
{
Display(ADC10,0);
Display(ADC1,1);
}
while(Flag_main)
{
if(Bulk_Out_Data_Buff[10]==0x6f)
{
Bulk_In_Data_Buff[0]=0x80;
Bulk_In_Data_Buff[1]=20;
Bulk_In_Data_Buff[10] =0x33;
Bulk_In_Data_Buff[11] =0x55;
cTmp=Bulk_In_Data_Buff[1];
Send_Data(Bulk_In_Data_Buff,cTmp+10);
}
else
{
Bulk_In_Data_Buff[0]=0x80;
Bulk_In_Data_Buff[1]=20;
Bulk_In_Data_Buff[10] =0x11;
Bulk_In_Data_Buff[11] =0x22;
Bulk_In_Data_Buff[19] =0x99;
cTmp=Bulk_In_Data_Buff[1];
Send_Data(Bulk_In_Data_Buff,cTmp+10);
}
Flag_main=FALSE;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -