void Tamper_check() { unsigned char Tamper_sum,Tamper_No; char Menu_Index; unsigned char temp,temp_Dir; if((ST87_tamper_check())==1) { lcd_clear(); printf("New Tamper event" ); ST87_tamper_save(); lcd_clear(); printf("Turning Encoder\n" "for looking TR"); delay_1sec(); delay_1sec(); Tamper_sum=Turbo_SPI_ReadByte(0x0000); Tamper_No=Turbo_SPI_ReadByte(0x0001); if(Tamper_sum>Tamper_No)temp=Tamper_sum; else temp=Tamper_No; Menu_Index=0; ST87_tamper_Show(Menu_Index); while((PSD8xx_reg.DATAIN_B&0x10)!=0) { temp_Dir=Polling_Encoder(); if(temp_Dir==2) { Menu_Index++; if(Menu_Index>=temp)Menu_Index=0; ST87_tamper_Show(Menu_Index); } else if(temp_Dir==1) { Menu_Index--; if(Menu_Index<0)Menu_Index=temp-1; ST87_tamper_Show(Menu_Index); } PSD8xx_reg.DIRECTION_B|=0x10; PSD8xx_reg.DATAOUT_B|=0x10; PSD8xx_reg.DIRECTION_B&=0xEF; // IN direction } lcd_clear(); } else { //printf("Old Tamper record" ); } }
interrupt void isr_t0() { init_timer(); delay_1sec(); //buzzer(); scanner(); if(s1_over==1) { incrementd(); s1_over=0; } }
int main(int argc, char **argv) { bool flip_flop = false; asm ("di"); /* Setup clocks */ CMC = 0x11U; /* Enable XT1, disable X1 */ CSC = 0x80U; /* Start XT1 and HOCO, stop X1 */ CKC = 0x00U; delay_1sec(); OSMC = 0x00; /* Supply fsub to peripherals, including Interval Timer */ uart0_init(); #if __GNUC__ /* Force linking of custom write() function: */ write(1, NULL, 0); #endif /* Setup 12-bit interval timer */ RTCEN = 1; /* Enable 12-bit interval timer and RTC */ ITMK = 1; /* Disable IT interrupt */ ITPR0 = 0; /* Set interrupt priority - highest */ ITPR1 = 0; ITMC = 0x8FFFU; /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */ ITIF = 0; /* Clear interrupt request flag */ ITMK = 0; /* Enable IT interrupt */ /* asm ("ei"); / * Enable interrupts * / */ /* Disable analog inputs because they can conflict with the SPI buses: */ ADPC = 0x01; /* Configure all analog pins as digital I/O. */ PMC0 &= 0xF0; /* Disable analog inputs. */ clock_init(); /* Initialize Joystick Inputs: */ PM5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Set pins as inputs. */ PU5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Enable internal pull-up resistors. */ /* Initialize LED outputs: */ #define BIT(n) (1 << (n)) PM12 &= ~BIT(0); /* LED1 */ PM4 &= ~BIT(3); /* LED2 */ PM1 &= ~BIT(6); /* LED3 */ PM1 &= ~BIT(5); /* LED4 */ PM0 &= ~BIT(6); /* LED5 */ PM0 &= ~BIT(5); /* LED6 */ PM3 &= ~BIT(0); /* LED7 */ PM5 &= ~BIT(0); /* LED8 */ #if UIP_CONF_IPV6 #if UIP_CONF_IPV6_RPL printf(CONTIKI_VERSION_STRING " started with IPV6, RPL" NEWLINE); #else printf(CONTIKI_VERSION_STRING " started with IPV6" NEWLINE); #endif #else printf(CONTIKI_VERSION_STRING " started" NEWLINE); #endif /* crappy way of remembering and accessing argc/v */ contiki_argc = argc; contiki_argv = argv; process_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); queuebuf_init(); netstack_init(); printf("MAC %s RDC %s NETWORK %s" NEWLINE, NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name); #if WITH_UIP6 memcpy(&uip_lladdr.addr, serial_id, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); printf("Tentative link-local IPv6 address "); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } /* make it hardcoded... */ lladdr->state = ADDR_AUTOCONF; printf("%02x%02x" NEWLINE, lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } #else process_start(&tcpip_process, NULL); #endif serial_line_init(); autostart_start(autostart_processes); while(1) { watchdog_periodic(); if(NETSTACK_RADIO.pending_packet()) { int len; packetbuf_clear(); len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); if(len > 0) { packetbuf_set_datalen(len); NETSTACK_RDC.input(); } } while(uart0_can_getchar()) { char c; UART_RX_LED = 1; c = uart0_getchar(); if(uart0_input_handler) { uart0_input_handler(c); } } UART_RX_LED = 0; process_run(); etimer_request_poll(); HEARTBEAT_LED1 = flip_flop; flip_flop = !flip_flop; HEARTBEAT_LED2 = flip_flop; } return 0; }
void main(void) { unsigned char k,ADC_channel; char Menu_Index; unsigned int ADC_result; unsigned long Wait_set_time; unsigned char Update_time, temp_Dir; unsigned char LcdContrast; PSD8xx_reg.VM |= 0x80; //Enable peripheral I/O timer0_init(); Turbo_ADC_Init(7); P4_0=0; lcd_init(); printf("DK3300 Demo V0.9\n" "STMicroelectric"); delay_1sec(); delay_1sec(); lcd_init(); printf("Turn Encoder R/L\n" "Press to Select"); delay_1sec(); delay_1sec(); delay_1sec(); //-----Initiate PB[4] as MCU input for encoder (PB[2,3] as logic input)------------- PSD8xx_reg.CONTROL_B&=0xEF; // MCU IO/Address OUT: mode PSD8xx_reg.DRIVE_B&=0xEF; // OpenDrain & SlewRate control PSD8xx_reg.DIRECTION_B|=0x10; PSD8xx_reg.DATAOUT_B|=0x10; PSD8xx_reg.DIRECTION_B&=0xEF; // IN direction //-----Waiting user select a demo to run----------------------------------------- // use OMC_AB[0,1] as a 2-bit counter to identify running of Encoder // use OMC_AB[2] as a running direction indication of Encoder //------------------------------------------------------------------------------- Menu_Index=0; PSD8xx_reg.OMC_AB&=0xF8; PSD8xx_reg.OMC_AB|=0x04; Show_Menu (Menu_Index); while((PSD8xx_reg.DATAIN_B&0x10)!=0) { temp_Dir=Polling_Encoder(); if(temp_Dir==2) { Menu_Index++; if(Menu_Index==4)Menu_Index=0; Show_Menu (Menu_Index); } else if(temp_Dir==1) { Menu_Index--; if(Menu_Index==-1)Menu_Index=3; Show_Menu (Menu_Index); } PSD8xx_reg.DIRECTION_B|=0x10; PSD8xx_reg.DATAOUT_B|=0x10; PSD8xx_reg.DIRECTION_B&=0xEF; // IN direction } //-----Running the demo code user selected---------------------------------------- switch(Menu_Index) { case 0: //============================ Demo0: PWM ADC ==================================== PSD8xx_reg.CONTROL_B&=0xF1; // MCU IO/Address OUT: mode PSD8xx_reg.DRIVE_B&=0xF1; // OpenDrain & SlewRate control PSD8xx_reg.DIRECTION_B|=0x07; PSD8xx_reg.DATAOUT_B&=0xF1; lcd_init(); printf("PWM/ADC Demo\n" ); ADC_channel=7; ACON |= 0x20; // Enable ADC k=0; while(1){ if (k == 0) k = 0xff; // Fix over flow of 0H -> 0FFh if (k == 0xf) k = 0; // Fix over flow from 0FFh -> 0Fh PWM_Mode1_Init(0, k); delay_1sec(); // wait for voltage to settle printf("PWM=%02bX",k); //display adc channel and adc value on LCD Turbo_ADC_Init(ADC_channel); // Init & read ADC channel ADC_result=Turbo_ADC_Read(ADC_channel); printf(" ADC=%03X\r", ADC_result); // display adc channel and adc value on LCD k = k + 0x10; } break; case 1: //============================ Demo1: I2C RTC ===================================== //---------------------- Check RTC tamper function ----------------------------------------- lcd_init(); Turbo_i2c_init(); ST87_tamper_init(); Turbo_SPI_Init(); Tamper_check(); //---------------------- Waiting user set time ----------------------------------------- lcd_init(); printf("Turn Encoder to\n" "set Date & Time" ); delay_1sec(); delay_1sec(); Turbo_i2c_init(); ST85_read(); st85.second=i2c_rcv_buf[1]; st85.minute=i2c_rcv_buf[2]; st85.hour=i2c_rcv_buf[3]; st85.day=i2c_rcv_buf[5]; st85.month=i2c_rcv_buf[6]; st85.year=i2c_rcv_buf[7]; lcd_init(); Menu_Index=0; PSD8xx_reg.OMC_AB&=0xF8; PSD8xx_reg.OMC_AB|=0x04; PSD8xx_reg.DIRECTION_B|=0x10; PSD8xx_reg.DATAOUT_B|=0x10; PSD8xx_reg.DIRECTION_B&=0xEF; // IN direction Show_time(Menu_Index); Wait_set_time=0; Update_time=0; while((PSD8xx_reg.DATAIN_B&0x10)!=0) { temp_Dir=Polling_Encoder(); if(temp_Dir==2) { Menu_Index++; if(Menu_Index==6)Menu_Index=0; Show_time(Menu_Index); Update_time=1; } else if(temp_Dir==1) { Adjust_time(Menu_Index); Show_time(Menu_Index); Update_time=1; } PSD8xx_reg.DIRECTION_B|=0x10; PSD8xx_reg.DATAOUT_B|=0x10; PSD8xx_reg.DIRECTION_B&=0xEF; // IN direction if(Update_time==0)Wait_set_time++; if(Wait_set_time>200000)break; } //----------------------------Save time into ST85------------------------------------- if(Update_time==1) { i2c_xmit_buf[2]=st85.second; i2c_xmit_buf[3]=st85.minute; i2c_xmit_buf[4]=st85.hour; i2c_xmit_buf[6]=st85.day; i2c_xmit_buf[7]=st85.month; i2c_xmit_buf[8]=st85.year; ST85_write(); } else { ST85_config(); } lcd_init(); // initialize LCD. 8 bits, 2 lines, 5x7 font, while (TRUE){ ST85_read(); // Read & Print ST85 printf("Turbo I2C Demo\n" "Time: %02bX:%02bX:%02bX\n",i2c_rcv_buf[3],i2c_rcv_buf[2],i2c_rcv_buf[1]); Tamper_check(); if(Key_check()==3) { ST87_tamper_clear(); lcd_clear(); printf("Tamper record \n" "has been removed!"); delay_1sec(); delay_1sec(); lcd_clear(); } } break; case 2: //============================ Demo2: PWMLCD ================================================= lcd_init(); printf("JP3:PWM\n" "JP14:Open\n"); delay_1sec(); while((PSD8xx_reg.DATAIN_B&0x10)!=0); lcd_clear(); printf("PWMLCD Demo\n"); PwmInit_Mode1(0xC0); LcdContrast=0xC0; while (1) { temp_Dir=Polling_Encoder(); if(temp_Dir==2) { if (++LcdContrast==0) LcdContrast=255; } else if(temp_Dir==1) { if (--LcdContrast==0xff) LcdContrast=0; } PwmSetDuty_Mode1(LcdContrast); printf("Brightness:%02bX\r",LcdContrast); } break; case 3: //============================ Demo3: IrDA ================================================ lcd_init(); printf("Under\n" "construction..."); while(1); break; } }