Example #1
0
	//-------------------------
	void servo_buka(){
			//Assignment variabel PWM
			UNLOCKREG();
			SYSCLK->PWRCON.XTL12M_EN=1;
			DrvSYS_Delay(5000);					// Waiting for 12M Xtal stalble
			SYSCLK->CLKSEL0.HCLK_S=0;
			LOCKREG();

			//init_LCD();
			//clear_LCD();

			// PWM_No = PWM channel number
			// PWM_CLKSRC_SEL   = 0: 12M, 1:32K, 2:HCLK, 3:22M
			// PWM_PreScaler    : PWM clock is divided by (PreScaler + 1)
			// PWM_ClockDivider = 0: 1/2, 1: 1/4, 2: 1/8, 3: 1/16, 4: 1
			init_PWM(0, 0, 130, 4); // initialize PWM0(GPA12) to output 1MHz square wave
			Clock = 12000000;
			PreScaler = 130;
			ClockDivider = 1;
			Frequency = 50;

			//hitime = SERVO_HITIME_MIN;
			//--------------------------------------

			//----------Kodingan inti microservo
			//hitime=hitime + (SERVO_HITIME_MAX - SERVO_HITIME_MIN)/10;
			hitime = 125;
			if (hitime>SERVO_HITIME_MAX) hitime = SERVO_HITIME_MIN;
			//PWM_FreqOut = PWM_Clock / (PWM_PreScaler + 1) / PWM_ClockDivider / (PWM_CNR + 1)
			CNR = Clock / Frequency / (PreScaler + 1) / ClockDivider - 1;
			// Duty Cycle = (CMR0+1) / (CNR0+1)
			CMR = hitime  - 1;
			//CMR = 20;
			PWM_Out(0, CNR, CMR);
		}
Example #2
0
int main(void)
{
	DrvUART_Close(UART_PORT0);
	//------------------
    Init();
    Initial_pannel();
    clr_all_pannal();
    while(1)
       {
    	seg_display(hitung);

    	/*UNLOCKREG();
    	SYSCLK->PWRCON.XTL12M_EN = 1;//Enable 12MHz Crystal
    	SYSCLK->CLKSEL0.HCLK_S = 0;
    	LOCKREG();*/
    	servo_tutup();
    	//DrvSYS_Delay(10);
    	Initial_pannel();
    	DrvGPIO_ClrBit(E_GPD, 14);

    	print_lcd(0,"Selamat Datang");
    	print_lcd(1,"1. Kumpul Borang");
    	print_lcd(2,"2. Absen Doang");
    	print_lcd(3," > Silakan Tekan:");
    	//DrvSYS_Delay(10000);

    	key=Scankey();
    	while(key==4){
           	       		bacarfid();
           	       	}


       	while(key==1){
      kumpul();
       	}

       	while (key==2){
       		absen();
       print_lcd(2,"3. ADC=");
       	DrvADC_StartConvert();
       	adc=DrvADC_GetConversionData(7);
       	Show_Word(3,5,adc/1000+'0');
       	Show_Word(3,6,adc%1000/100+'0');
       	Show_Word(3,7,adc%100/10+'0');
       	Show_Word(3,8,adc%10+'0');

       	}




       	DrvGPIO_SetBit(E_GPC,12);
       	DrvSYS_Delay(1000);


       }
}
Example #3
0
void WriteLCM(int32_t data_comm,int32_t in_com)			//1 for data,0 for comm
{  
   int32_t com,i,j,std;
       DrvSYS_Delay(100);
   	    	com = in_com;

		  DrvGPIO_ClrBit( E_GPC,3); //LCD_EN = 0;
    	  DrvGPIO_SetBit(E_GPC,2);//LCD_STD = 1;
	     	for(i=5;i>0;i--)
			{
  			DrvGPIO_SetBit( E_GPC,3); //LCD_EN = 1;
			DrvGPIO_ClrBit( E_GPC,3); //LCD_EN = 0;			
			}

  			DrvGPIO_ClrBit(E_GPC,2);//LCD_STD = 0;
   			DrvGPIO_SetBit( E_GPC,3); //LCD_EN = 1;
			DrvGPIO_ClrBit( E_GPC,3); //LCD_EN = 0;

			if(data_comm==1)
				DrvGPIO_SetBit(E_GPC,2);//LCD_STD = 1;	   11111010
			else
    			DrvGPIO_ClrBit(E_GPC,2);//LCD_STD = 0;	   11111000
   			DrvGPIO_SetBit( E_GPC,3); //LCD_EN = 1;
			DrvGPIO_ClrBit( E_GPC,3); //LCD_EN = 0;

      			DrvGPIO_ClrBit(E_GPC,2);//LCD_STD = 0;
			DrvGPIO_SetBit( E_GPC,3); //LCD_EN = 1;
			DrvGPIO_ClrBit( E_GPC,3); //LCD_EN = 0;
  
	for(j=2;j>0;j--)
	{
		for(i=4;i>0;i--)
		{
			
			std=com&0x80;
			if(std==0x80)
				DrvGPIO_SetBit(E_GPC,2);   //LCD_STD = 1;	
			else
				DrvGPIO_ClrBit(E_GPC,2);   //LCD_STD = 0;	
				com=com<<1;
			DrvGPIO_SetBit( E_GPC,3); //LCD_EN = 1;
			DrvGPIO_ClrBit( E_GPC,3); //LCD_EN = 0;
		}
		DrvGPIO_ClrBit(E_GPC,2);   //LCD_STD = 0;
		for(i=4;i>0;i--)
		{
			DrvGPIO_SetBit( E_GPC,3); //LCD_EN = 1;
			DrvGPIO_ClrBit( E_GPC,3); //LCD_EN = 0;
		}
	}
} 
void SystemClockInit(void)
{
   UNLOCKREG();

   DrvSYS_SetOscCtrl(E_SYS_XTL12M, ENABLE);
   DrvSYS_Delay(5000);
   DrvSYS_Open(50000000);



   /* Enable PLL */
   //DrvSYS_SetPLLMode(0);

   /* Switch to PLL clock */
  // DrvSYS_SelectHCLKSource(2);

   /* Update system core clock */
   //SystemCoreClockUpdate();
}
Example #5
0
void LCMInit(void)		//LCM初始化
{ 
	DrvGPIO_ClrBit(E_GPC,5 );
    DrvSYS_Delay(6000);
 	DrvGPIO_SetBit(E_GPC,5 );  
    WriteLCM(0,0x30)	;			 //设接口数据位数(DL),显示行数(L),及字型(F)
    DrvSYS_Delay(6000);
	WriteLCM(0,0x01)	;		 //清屏指令
    DrvSYS_Delay(6000);	
	WriteLCM(0,0x0c)	;	   //设整体显示开关(D),光标开关关(C),及光标位的字符不闪耀(B)
    DrvSYS_Delay(6000);
	WriteLCM(0,0x06)	;	   //7设光标移动方向并指定整体显示是否移动
    DrvSYS_Delay(6000);
	WriteLCM(0,0x01)	;		//清屏指令
    DrvSYS_Delay(6000); 	
	WriteLCM(0,0x80)	;		//设DDRAM地址,设置后DDRAM数据被发送和接收
}
Example #6
0
int main(void)
{
    uint8_t buffer[32] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
    /* Unlock the protected registers */
    UNLOCKREG();

    /* Enable the 12MHz oscillator oscillation */
    DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);

    /* Waiting for 12MHz Xtal stable */
    DrvSYS_Delay(5000);

    /* HCLK clock source. 0: external 12MHz. */
    DrvSYS_SelectHCLKSource(0);

    LOCKREG();

    DrvSYS_SetClockDivider(E_SYS_HCLK_DIV, 0); /* HCLK clock frequency = HCLK clock source / (HCLK_N + 1) */

    nrf_init();

    nrf_detect();

    //nrf_rx_mode_no_aa(addr,5,16,40);
    //nrf_rx_mode(addr,5,16,40);
    nrf_rx_mode_dual(addr,5,40);

    nrf_test_reg();

    DrvGPIO_Open(E_GPA, 2, E_IO_OUTPUT);
    DrvGPIO_Open(E_GPA, 3, E_IO_OUTPUT);
    DrvGPIO_Open(E_GPA, 4, E_IO_OUTPUT);
    DrvGPIO_Open(E_GPA, 5, E_IO_OUTPUT);
    {
        uint8_t status = nrf_read_reg(NRF_STATUS);
        nrf_write_reg(NRF_WRITE_REG|NRF_STATUS,status); // clear IRQ flags
        nrf_write_reg(NRF_FLUSH_RX, 0xff);
        nrf_write_reg(NRF_FLUSH_TX, 0xff);
    }

    while(1) {
        uint8_t buffer[32];
        if(tx_done) {
            static uint8_t yy = 0;
            yy++;
            if(yy&1) {
                DrvGPIO_SetBit(E_GPA,2);
            } else {
                DrvGPIO_ClrBit(E_GPA,2);
            }
            if(tx_done == 1) {
            } else {
            }
            buffer[0] = tx_done;
            tx_done = 0;
        }
        if(rx_done) {
            static uint8_t xx = 0;
            rx_done = 0;
            xx++;
            if(xx & 1)
                DrvGPIO_SetBit(E_GPA,5);
            else
                DrvGPIO_ClrBit(E_GPA,5);

            //nrf_ack_packet(0,buffer, (xx&15) + 1);
            nrf_ack_packet(0,rx_buffer, rx_len);
        }
    }

    while(1) {
        static uint8_t cnt = 0;
        if(cnt&1) {
            DrvGPIO_SetBit(E_GPA,2);
        } else {
            DrvGPIO_ClrBit(E_GPA,2);
        }
        DrvSYS_Delay(50000*2);
        cnt++;
        //nrf_tx_packet(buffer, 16);
        //buffer[0]++;

        if(nrf_rx_packet(buffer,16) == NRF_RX_OK)
        {
            static uint8_t xx = 0;
            xx++;
            if(xx & 1)
                DrvGPIO_SetBit(E_GPA,5);
            else
                DrvGPIO_ClrBit(E_GPA,5);
        }
    }
    return 0;
}
Example #7
0
//*****************************************************************************
//
//! \brief PWM Output.
//!
//! \param None  
//!
//! \return None  
//
//*****************************************************************************
void PWMOutput(void)
{
    S_DRVPWM_TIME_DATA_T sPt;
    int32_t i32Loop = 1;

    UNLOCKREG();
    //
    // P5.1 -> XTAL2, P5.0 -> XTAL1
    //
    GCR->P5_MFP = (GCR->P5_MFP & 0x00FFFCFC) | 0x03;
    CLK->PWRCON_BITS.XTLCLK_EN = 1;

    //
    // Waiting for 12M Xtal stalble
    //
    DrvSYS_Delay(5000);
     
    //
    //Enable PWM clock
    //
    DrvPWM_Open();
	  CLK->CLKSEL1_BITS.PWM23_S = 2;
    
    //
    // Set PWM pin
    //
    DrvGPIO_InitFunction(FUNC_PWM3);

    UNLOCKREG();
    DrvSYS_SelectHCLKSource(0);
    LOCKREG();

    while(i32Loop)
    {

        uint8_t u8ItemOK;

        u8ItemOK = 1;
        g_u16Frequency = 256;


        if (u8ItemOK && g_u8PWMCount == 0)
        {
            s_u32Pulse = 0;
            g_u8PWMCount = 1;
            //
            // PWM Timer property
            //
            sPt.u8Mode = DRVPWM_AUTO_RELOAD_MODE;
            sPt.u32Frequency = g_u16Frequency;
            //
            // High Pulse peroid : Total Pulse peroid = 10 : 90
            //
            sPt.u8HighPulseRatio = 90;
            sPt.i32Inverter = 0;
            
            //
            // Set PWM Timer Configuration 
            //
            DrvPWM_SetTimerClk(DRVPWM_TIMER3, &sPt);

            //
            // Enable Output for PWM Timer */
            //
            DrvPWM_SetTimerIO(DRVPWM_TIMER3, 1);
            
            //
            // Enable Interrupt Sources of PWM Timer and install call back function
            //
            DrvPWM_EnableInt(DRVPWM_TIMER3, PWM_INT_PERIOD, PWMA_IRQHandler, 0);
            
            //
            //Enable the PWM Timer
            //
            DrvPWM_Enable(DRVPWM_TIMER3);

            while (g_u8PWMCount);
            DrvPWM_Disable(DRVPWM_TIMER3);
          }
    }
    DrvPWM_Close();
}
Example #8
0
void absen(){
	uint8_t hasiluart[8];
	clr_all_pannal();

		while(key==2){
	       	DrvGPIO_ClrBit(E_GPC,12);
	       	DrvSYS_Delay(10000);
	       	print_lcd(0,"Tap Kartu Anda");
	       	print_lcd(1,"Pada Reader");
	       	bacarfid();
	       	DrvUART_Read(UART_PORT0,hasiluart,1);
	       	if(hasiluart[0]=='B'){
	       	       	clr_all_pannal();
	       	       	       		    print_lcd(0,"Terima Kasih :)");
	       	       	       		    print_lcd(1,"Tito Alvi");
	       	       	       		    hitungabsen++;
	       	       	       		    			DrvGPIO_ClrBit(E_GPB,11);
	       	       	       		        		DrvSYS_Delay(100000);
	       	       	       		        		DrvGPIO_SetBit(E_GPB,11);
	       	       	       		        		DrvSYS_Delay(100000);
	       	       	       		        		DrvGPIO_ClrBit(E_GPB,11);
	       	       	       		        		DrvSYS_Delay(100000);
	       	       	       		        		DrvGPIO_SetBit(E_GPB,11);
	       	       	       		        		DrvSYS_Delay(100000);
	       	       	       		        		DrvGPIO_ClrBit(E_GPB,11);
	       	       	       		        		DrvSYS_Delay(100000);
	       	       	       		        		DrvGPIO_SetBit(E_GPB,11);
	       	       	       		        		DrvSYS_Delay(100000);
	       	       	       		    print_lcd(0,"Terima Kasih :)");
	       	       	       			DrvSYS_Delay(5000000);

	       	       	       			main();
	       	       	}
	       	if(hasiluart[0]!='B'){
	       		clr_all_pannal();
	       		print_lcd(0,"Maaf :(");
	       		print_lcd(1,"Nama kamu gak");
	       		print_lcd(2,"Ada di Basis Data");
	       		print_lcd(3,"COBA LAGI !!!");
	       		DrvGPIO_ClrBit(E_GPB,11);
	       			       		DrvSYS_Delay(500000);
	       			       		DrvGPIO_SetBit(E_GPB,11);
	       			       		DrvSYS_Delay(100000);
	       			       		DrvGPIO_ClrBit(E_GPB,11);
	       			       		DrvSYS_Delay(500000);
	       			       		DrvGPIO_SetBit(E_GPB,11);
	       			       		DrvSYS_Delay(100000);
	       			       	delay(5000000);
	       		DrvSYS_Delay(2000000);
	       		absen();
	       	}



		}
}
Example #9
0
void kumpul(){
	clr_all_pannal();
	uint8_t hasiluart[8];
	while(key==1){
       	DrvGPIO_ClrBit(E_GPC,12);
       	DrvSYS_Delay(10000);
       	DrvGPIO_ClrBit(E_GPB,0);
       	print_lcd(0,"Tap Kartu Anda");
       	print_lcd(1,"Pada Reader");
       	print_lcd(2,"Tekan Button");
       	print_lcd(3,"untuk Kembali");
       	if(DrvGPIO_GetBit(E_GPB,15)==0){
       	       		main();}
       	bacarfid();
		DrvUART_Read(UART_PORT0,hasiluart,1);
		if(hasiluart[0]=='B'){
						DrvGPIO_ClrBit(E_GPB,11);
			       		DrvSYS_Delay(100000);
			       		DrvGPIO_SetBit(E_GPB,11);
			       		DrvSYS_Delay(100000);
			       		DrvGPIO_ClrBit(E_GPB,11);
			       		DrvSYS_Delay(100000);
			       		DrvGPIO_SetBit(E_GPB,11);
			       		DrvSYS_Delay(100000);
			       		clr_all_pannal();
			       		goto benar;
		}
		if(hasiluart[0]!='B'){
			SYSCLK->PWRCON.XTL12M_EN = 1;//Enable 12MHz Crystal
			       		       							SYSCLK->CLKSEL0.HCLK_S = 0;
			       		       						LOCKREG();
			       		clr_all_pannal();
			       		print_lcd(0,"Maaf :(");
			       		print_lcd(1,"Nama kamu gak");
			       		print_lcd(2,"Ada di Basis Data");
			       		print_lcd(3,"COBA LAGI !!!");
			       		DrvGPIO_ClrBit(E_GPB,11);
			       						DrvGPIO_ClrBit(E_GPB,11);
			       			       		DrvSYS_Delay(500000);
			       			       		DrvGPIO_SetBit(E_GPB,11);
			       			       		DrvSYS_Delay(100000);
			       			       		DrvGPIO_ClrBit(E_GPB,11);
			       			       		DrvSYS_Delay(500000);
			       			       		DrvGPIO_SetBit(E_GPB,11);
			       			       		DrvSYS_Delay(100000);
			       			       		DrvGPIO_ClrBit(E_GPB,11);
			       			       		delay(5000000);
			       		kumpul();
			       	}
       	//key2=Scankey();
       	/*if(key2==2){
       		DrvGPIO_ClrBit(E_GPB,11);
       		DrvSYS_Delay(100000);
       		DrvGPIO_SetBit(E_GPB,11);
       		DrvSYS_Delay(100000);
       		DrvGPIO_ClrBit(E_GPB,11);
       		DrvSYS_Delay(100000);
       		DrvGPIO_SetBit(E_GPB,11);
       		DrvSYS_Delay(100000);
       		clr_all_pannal();
       	}*/
       	//mennu harus diubah klo uart dah jadi
		benar:
       	while(hasiluart[0]=='B'){
       		print_lcd(0,"Silakan Masukkan");
       		print_lcd(1,"Borang Kamu");
       		SYSCLK->PWRCON.XTL12M_EN = 1;//Enable 12MHz Crystal
       		       							SYSCLK->CLKSEL0.HCLK_S = 0;
       		       						LOCKREG();
       		       				        servo_buka();
       		       				        DrvSYS_Delay(10);
       		Scankey();
       		if(DrvGPIO_GetBit(E_GPA,0)==0){
       		    clr_all_pannal();
       		    print_lcd(0,"Terima Kasih :)");
       		    print_lcd(1,"Tito Alvi");
       		    hitung++;
       		 DrvGPIO_ClrBit(E_GPB,11);
       		 			       		DrvSYS_Delay(100000);
       		 			       		DrvGPIO_SetBit(E_GPB,11);
       		 			       		DrvSYS_Delay(100000);
       		 			       		DrvGPIO_ClrBit(E_GPB,11);
       		 			       		DrvSYS_Delay(100000);
       		 			       		DrvGPIO_SetBit(E_GPB,11);
       		 			       		DrvSYS_Delay(100000);
       		 			       	DrvGPIO_ClrBit(E_GPB,11);
       		 			       	DrvSYS_Delay(100000);
       		 			       	DrvGPIO_SetBit(E_GPB,11);
       		 			       	DrvSYS_Delay(100000);
       		    print_lcd(0,"Terima Kasih :)");
       			DrvSYS_Delay(2000000);
       			main();
       		       	}
       		while(DrvGPIO_GetBit(E_GPA,0)==0){ //sensor cahaya = GPA0 - SIG
       			       				         			       		main();}
       		}

       	}


       	       	}