Ejemplo n.º 1
0
int main(void) {
	volatile unsigned char a;
	volatile unsigned int i; // volatile to prevent optimization
	WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
	// setup pprt 3 as an output so to be able to turn on the LED
	P2DIR |= 0x02; // Set P1.0 to output direction
	// go Initialize the LCD
	Init_LCD();

	while (1)
		for (a = 0; a < 0x10; a++) {
			LCDSeg[0] = Digits[a];

			i = -1; // SW Delay
			do
				i--;
			while (i != 0);
		}

	// now that all the LCD segments have been turned on just toggle
	// the yellow LED on / off
	for (;;) {
		P2OUT ^= 0x02; // Toggle P1.0 using exclusive-OR
		i = 10000; // SW Delay
		do
			i--;
		while (i != 0);
	}
}
Ejemplo n.º 2
0
void main(void)
{
	Init_Ports();                             // Initialize Ports
	Init_Clocks();                            // Initialize Clock System 
	Init_Conditions();
	Init_Interrupts();
	  
	TimeMsec = RESET_TIME;
	Init_Timers(); 				// Initialize Timers
	Init_LCD();				// Initialize LCD    
        
        
	//          "0123456789abcdef"
	display_1 = "   Homework 9   ";
	display_2 = "                ";
	Display_Process();
	
/* ---------- Begining of the "While" Operating System ------------- */
	while(ALWAYS) 										// Can the Operating system run
	{                            
                ADC_Process();
                Control_Process();
                Menu_Process();
                
          
                if(TimeMsec % EVERY_50 == RESET_TIME)
                {
                        Display_Process();
                }	
	}
}
Ejemplo n.º 3
0
//main function
void main(void)
{
    unsigned char st1[]="STARTING";
    unsigned char st2[]=".";

    //pins for drive LCD
    TRISB = 0x80;

    //Initialize modules
    Init_LCD();
    i2c_config();

    set_ds1307_time(AM,0,0,6);
    set_ds1307_day(8,11,8,13);

    lcd_putstr(st1);

    for(i=0;i<7;i++)
    {
        lcd_putstr(st2);
        Delay1KTCYx(200);
    }
    LCD_CMD(LCD_clear);
    
    while(1)
    {
        lcd_gotoxy(1,1);//hang 1, cot 1.
        Display_time(get_ds1307_time());

        lcd_gotoxy(1,2);//hang 2, cot 1
        Display_day(get_ds1307_day());

        Delay10KTCYx(70);
    };
}
Ejemplo n.º 4
0
int main(void) {
	volatile unsigned char a;
	volatile unsigned char swStatus;
	volatile unsigned int i; // volatile to prevent optimization
	volatile unsigned int number;
	WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
	// setup pprt 3 as an output so to be able to turn on the LED
	P2DIR |= 0x02; // Set P1.0 to output direction
	P1DIR &= ~0x03; // Enable switches as inputs
	// go Initialize the LCD
	Init_LCD();
	number = 0x00;
	while (1) {
		if ((P1IN & 0x3) == 0x01)
			number -= 1;
		else if((P1IN & 0x3) == 0x02)
			number += 1;

		number = RollOverForDec(number);
		SetLCD(number);

		i = 0x0FFF; // SW Delay
		while (i != 0)
			i--;
	}

}
Ejemplo n.º 5
0
int main(void) {
	volatile unsigned char a;
	volatile unsigned int i; // volatile to prevent optimization
	WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
	// setup pprt 3 as an output so to be able to turn on the LED
	P2DIR |= 0x02; // Set P1.0 to output direction
	// go Initialize the LCD
	Init_LCD();
	// Turn on all of the segments
	// LCD_SIZE-4 only gives the 7 segment displays plus DP,
	// and colons colons = dp
	// Right most display is at LCDSeg[0];
	for (i = 0; i < LCD_SIZE; i++) {
		// To turn on a segment of the LCD a one is written in the
		// appropriate location in the LCD memory
		// Setting all the bits to 1 for all memory locations turns on
		// all of the display elements
		// Including all of the special characters
		LCDSeg[i] = 0xff;
	}
	// now that all the LCD segments have been turned on just toggle
	// the yellow LED on / off
	for (;;) {
		P2OUT ^= 0x02; // Toggle P1.0 using exclusive-OR
		i = 10000; // SW Delay
		do
			i--;
		while (i != 0);
	}
}
Ejemplo n.º 6
0
/*******************************************************************************
 *
 *                      Initialize Function
 *
 *******************************************************************************/
void initialize() {
    /**************************************************
     *  Setting up for Clock (PLL, M, N1, N2)
     *  for 32 MHz and Fcy = 16 MHz
     *************************************************/
    // Fosc = Fin(M/(N1*N2)) = 8 MHz (32/(2*4)) = 32 MHz
    PLLFBD = 30; // M = 32
    // N1 default is 2
    // N2 default is 4
    // Fcy = Fosc/2 by default

     // Setting up RD6 and RD7
    _TRISD6 = 1;
    _TRISD7 = 1;                                    // Set RD6 & 7 to inputs

    // Initialize LCD
    Init_LCD();

    lcd_cmd(0xD);

    // Making sure that we are starting at line 1, column 0
    home_it();
    // Print the LcdData1
    puts_lcd(LcdData1, sizeof(LcdData1)-1);
    // Move to next line
    line_2();
    // Print the LCDData2
    puts_lcd(LcdData2, sizeof(LcdData2)-1);
}
Ejemplo n.º 7
0
void main(void){
//==============================================================================
// Main Program
// 
// Description: This function contains the while loop that runs continuously
// to act for the operating system. It also calls all the functions to
// initialize the system.
//
// Passed : no variables passed
// Locals: no variables declared
// Returned: no values returned
// Globals:     volatile unsigned int Time_Sequence;
//              volatile char one_time;
//              char* display_1
//              char* display_2
//              char* display_3
//              char* display_4
//              slow_input_down
//              control_state[CNTL_STATE_INDEX]
//              char big
//              char size_count;
//              char posL1
//              char posL2
//              char posL3
//              char posL4
//
// Author: David Pryor
// Date: Feb 2016
// Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1)
//==============================================================================
  Init_Ports();                             // Initialize Ports
  Init_Clocks();                            // Initialize Clock System 
  Init_Conditions();
  Time_Sequence = SWITCH_OFF;               // 
  Init_Timers();                            // Initialize Timers
  Init_LEDs();                              // Initialize LEDs
  Init_LCD();                               // Initialize LCD
  Init_ADC();                               // Initialize ADC

//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
  while(ALWAYS) {                            // Can the Operating system run
    Menu_Process();
    ADC_Process();              // call sampling function
    if(display_count >= FOR_FOURTH_SECOND){    // update screen every 250 msec
      Display_Process();
      display_count = SWITCH_OFF;
    }
    if(menu_items == FALSE){  
      display_4 = "SW2: Menu";
    }
    if(switch_two_pressed){
      menu_items = TRUE;
      switch_two_pressed = SWITCH_OFF;
    }
  }
//------------------------------------------------------------------------------
}
Ejemplo n.º 8
0
int show_lcd(void){
	volatile unsigned char a; volatile unsigned int i;
	WDTCTL = WDTPW + WDTHOLD;
	Init_LCD();
	for (i=0;i<LCD_SIZE;i++)
	{
		LCDSeg[i]=0xff;
	}
	return 0;
}
Ejemplo n.º 9
0
static void InitializeSystem(void) {
    ADCON1 |= 0x0F;
//    TRISCbits.TRISC6=0;
//    TRISCbits.TRISC7 =0;
//    LATCbits.LATC6 =0;
//    LATCbits.LATC7=0;
    USBDeviceInit();
#if defined(USE_UART)
    Init_UART(BAUD_RATE);
    Init_Tran_UART();
    Init_Rec_UART();
#endif
#if defined(USE_LCD)
    Init_PORTS();
    Init_LCD();
#endif
}
Ejemplo n.º 10
0
int main(void) {
    if (SysTick_Config(SystemCoreClock / 1000)) {
        while (1) {};
    }
    Init_GPIO();
    Init_SPI();
    Init_RNG();
    Init_LCD();

    int counter=1;
    int counter2 =0;
    int x = 0;
    int y = 0;
    DrawFillRectangle(1,1,128,160,0xFFFFFF);
    for ( x = 160; x > 0; x-- )
        for ( y = 1; y <= 84; y++ )
            DrawFillRectangle(y+22, x, 1, 1, Image[(y-1)*160+161-x]-0x010101);
    while(1) {


        //DrawFillRectangle(RNG->DR%128,RNG->DR%160,RNG->DR%128,RNG->DR%160,RNG->DR);
        /*if ( counter2 == 60000 ) {
            DrawFillRectangle(counter-1, counter-1, 20, 20, 0x000000);
            DrawFillRectangle(counter, counter, 20, 20, RNG->DR);
            //DrawFillRectangle(1,1,128,160,0x00000);
            counter+=1;
            counter2=0;
        }
        counter2+=1;
        if ( counter == 108 ) {
            DrawFillRectangle(1,1,128,160,0x00000);
            counter = 0;
        }*/
        /*GPIOD->ODR^=GreenLed;
        Delay(1);
        GPIOD->ODR^=OrangeLed;
        Delay(1);
        GPIOD->ODR^=RedLed;
        Delay(1);
        GPIOD->ODR^=BlueLed;
        Delay(1);*/
    }
    return 0;
}
Ejemplo n.º 11
0
void main(void)
{
	Init_Ports();                             // Initialize Ports
	Init_Clocks();                            // Initialize Clock System 
	Init_Conditions();
	Init_Interrupts();
       
	//PJOUT |= LED1;                          // Turn LED 1 on to indicate boot
	  
	TimeMsec = RESET_TIME;
	Init_Timers(); 				// Initialize Timers
	Init_LCD();				// Initialize LCD
	//Init_LEDs();                            // Initialize LEDs       
        
        
        
	//          "0123456789abcdef"
	display_1 = "   PROJECT  5   ";
	display_2 = "                ";
	Display_Process();
	
	P1OUT |= IR_LED;
	waitMsec(10);
	
/* ---------- Begining of the "While" Operating System ------------- */
	while(ALWAYS) 										// Can the Operating system run
	{                            
		if(TimeMsec % EVERY_50 == RESET_TIME)
			Display_Process();					//Refreshes screen every 50 'ticks'
                
		if(TimeMsec % EVERY_2 == RESET_TIME)
		{
			Switches_Process();                 // Poll for switch state change every other 'tick'
			ADC_Process();
		}
		
		Motors_Process();
		Control_Process();
	}
}
Ejemplo n.º 12
0
void InterfaceInit()
{
  //reset and clear LCD screen
  clearLCD();
  Init_LCD();
}
Ejemplo n.º 13
0
void main(void){
//------------------------------------------------------------------------------
// Main Program
// This is the main routine for the program. Execution of code starts here.
// The operating system is Back Ground Fore Ground.
// 
//------------------------------------------------------------------------------
  
  init_ports();                            
  Init_Clocks();                            
  Init_Conditions();                     
  init_timers();                            
  five_msec_delay(QUARTER_SECOND);                      
  Init_LCD();  
  setup_sw_debounce();
  init_adc();
  P1OUT |= IR_LED;
  init_serial_uart();
  
  WDTCTL = WDTPW + WDTHOLD;
  
  setup_pwm();
  
  set_motor_speed(R_FORWARD, PWM_RES);
  set_motor_speed(L_FORWARD, PWM_RES);

  unsigned int time_sequence  = START_VAL;      // counter for switch loop
  unsigned int previous_count = START_VAL;      // automatic variable for
                                                // comparing timer_count
  unsigned int display_count = START_VAL;
  
  is_follow_running = FALSE;
  
//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
  while(ALWAYS) {                            // Can the Operating system run

    if(get_timer_count() > display_count + QUARTER_SECOND)
    {
      display_count = get_timer_count();
      Display_Process();
      time_sequence = START_VAL;
    }
    
    update_switches();                 // Check for switch state change
    update_menu();

    if(is_follow_running)
      run_follow();
    
    if(uca0_is_message_received())
    {
      BufferString message = uca0_read_buffer(TRUE);
      receive_command(message.head + message.offset);
    }
    
    if(uca1_is_message_received())
    {
      update_menu();
      BufferString message = uca1_read_buffer(TRUE);
      uca0_transmit_message(message.head, message.offset);
      if(find(WIFI_COMMAND_SYMBOL, message))
      {
        receive_command(message.head + message.offset);
      }
      if(find(LOST_WIFI_COMMAND_SYMBOL, message))
      {
        receive_command(CONNECT_NCSU);
      }
    }
    
    if(time_sequence > SECOND_AND_A_QUARTER)
      time_sequence = START_VAL;
    
    unsigned int current_timer_count = get_timer_count();
    
    if(current_timer_count > previous_count)
    {
      previous_count = current_timer_count % UINT_16_MAX;
      time_sequence++;
    } 
   }
//------------------------------------------------------------------------------
}
Ejemplo n.º 14
0
void main(void){
//==============================================================================
// Main Program
// 
// Description: This function contains the while loop that runs continuously
// to act for the operating system. It also calls all the functions to
// initialize the system.
//
// Passed : no variables passed
// Locals: no variables declared
// Returned: no values returned
// Globals:     volatile unsigned int Time_Sequence;
//              volatile char one_time;
//              char* display_1
//              char* display_2
//              char* display_3
//              char* display_4
//              slow_input_down
//              control_state[CNTL_STATE_INDEX]
//              char big
//              char size_count;
//              char posL1
//              char posL2
//              char posL3
//              char posL4
//
// Author: David Pryor
// Date: Feb 2016
// Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1)
//==============================================================================
  Init_Ports();                             // Initialize Ports
  Init_Clocks();                            // Initialize Clock System 
  Init_Conditions();
  Time_Sequence = SWITCH_OFF;               // 
  Init_Timers();                            // Initialize Timers
  five_msec_sleep(COUNT_TWOFIDDY_MSEC);     // 250 msec delay for the clock to settle (50)
  Init_LEDs();                              // Initialize LEDs
  Init_LCD();                               // Initialize LCD
  
//             1234567890
  display_1 = "NCSU";
  posL1 = LINE_POS_3;
  display_2 = "WOLFPACK";
  posL2 = LINE_POS_1;
  display_3 = "ECE306";
  posL3 = LINE_POS_2;
  display_4 = "D Pryor";
  posL4 = LINE_POS_1;
  big = SWITCH_OFF;
  Display_Process();
//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
 while(ALWAYS) {                            // Can the Operating system run
  switch(Time_Sequence){
    case COUNT_TWELVEFIDDY_MSEC:            // 1250 msec  (250)
      if(one_time){
        Init_LEDs();                        // Initialize LEDs
        one_time = SWITCH_OFF;
      }
      Time_Sequence = SWITCH_OFF;           // 
    case COUNT_ONETHOUSAND_MSEC:            // 1000 msec  (200)  
      if(one_time){
        one_time = SWITCH_OFF;
      }
    case COUNT_SEVENFIDDY_MSEC:             // 750 msec   (150) 
      if(one_time){
        one_time = SWITCH_OFF;
      }
    case COUNT_FIVEHUNNED_MSEC:             // 500 msec   (100) 
      if(one_time){
        one_time = SWITCH_OFF;
      }
    case  COUNT_TWOFIDDY_MSEC:  	    // 250 msec   (50)
      if(one_time){
        one_time = SWITCH_OFF;
      }
      size_count++;
      if(size_count > MAX_SIZE_COUNT){
        size_count = SWITCH_OFF;
        if(big){
          //lcd_BIG_mid();
          big = SWITCH_OFF;
        }else{
          //lcd_4line();
          big = SWITCH_ON;
        }
      }
        Display_Process();
      break;                                // 
    default: break; 
  }
  Switches_Process();                       // Check for switch state change 
  if(Time_Sequence > COUNT_TWELVEFIDDY_MSEC){
    Time_Sequence = SWITCH_OFF;
  }
 }
//------------------------------------------------------------------------------
}
Ejemplo n.º 15
0
int main(void) {
    /* Ledstrips inits */
    /* W5100 defines */
    unsigned char sockstat;
    unsigned int rsize;
    char radiostat0[10], radiostat1[10];
    int postidx, getidx;
    /* Initial variable used */
    sockreg = 0;
    tempvalue = 0;
    ledmode = 0;

    Init_timer1();
    Init_timers();
    /*Init_shift();*/
    OSCTUN = 21;
    PLLFBD = 38; /* M=40 */
    CLKDIVbits.PLLPOST = 0; /* N1=2 */
    CLKDIVbits.PLLPRE = 0; /* N2=2 */
   /* Eraseleds();*/
    /* even ledstrips have to be mirrored */
   /* Mirror(patt); */

    /* LCD inits */
    Init_mcp();
    Init_LCD();
    Write_LCD(startup);

    /* W5100 inits */
    Init_pin_SPI();
    Init_SPI();
    W5100_Init(gtw_addr,mac_addr,sub_mask,ip_addr);
    T_SPI_CS;
    SPI_CS = 1;

    Init_UART();

    for (;;) {

        sockstat = SPI_Read(S0_SR);
        switch (sockstat) {
            case SOCK_CLOSED:
                if (socket(sockreg, MR_TCP, TCP_PORT) > 0) {
                    /* Listen to Socket 0 */
                    if (listen(sockreg) <= 0)
                        Delayms(1);
                }
                break;

            case SOCK_ESTABLISHED:
                /* Get the client request size */
                rsize = recv_size();
                if (rsize > 0) {
                    /* Now read the client Request */
                    if (recv(sockreg, buf, rsize) <= 0)
                        break;

                    Putstr(buf);
/*                    printf("%s",buf);*/
                    /* Check the Request Header */
                    getidx = strindex((char *) buf, "GET /");
                    postidx = strindex((char *) buf, "POST /");

                     if (getidx >= 0 || postidx >= 0) {

                        /* Now check the Radio Button for POST request */
                        if (postidx >= 0) {
                            if (strindex((char *) buf, "uBoard new color") > 0)
                                ledmode++;
                        }


            /* Create the HTTP Response	Header */
	    strncpy((char *)buf,("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
                                "<body style=\"background-color:FFFFFF;\">\r\n"),96);

	    strcat((char *)buf,("[\n"
                                 "   {\n"
                                 "       \"id\": \"1\",\n"
                                 "       \"name\": \"uBoard webboard\",\n"
                                 "       \"ipaddr\": \"192.168.0.102\",\n"
                                 "       \"subnetmask\": \"255.255.255.0\",\n"
                                 "       \"gateway\": \"192.168.0.1\",\n"
                                 "       \"adjustSpeedOfPattern\": \"int\",\n"
                                 "       \"turnLedsOnOff\": \"boolean\"\n"
                                 "   }\n"
                                 "]\n"));




            /* Now Send the HTTP Response */
	    if (send(sockreg,buf,strlen((char *)buf)) <= 0) break;

            /* TODO: add status */
            LCD_Clear();
            LCD_PutByte(ledmode);
	    if (ledmode == 1) {
	      strncpy(radiostat0,"",0);
	      strncpy(radiostat1,("checked"),7);
	    } else {
	      strncpy(radiostat0,("checked"),7);
	      strncpy(radiostat1,"",0);
	    }

            /* Create the HTTP Radio Button Response */
	    strncpy((char *)buf,("<p><input type=\"radio\" name=\"radio\" value=\"0\" "),52);
	    strcat((char *)buf,radiostat0);
	    strcat((char *)buf,(">Turn off\r\n"));
	    strcat((char *)buf,("<br><input type=\"radio\" name=\"radio\" value=\"1\" "));
	    strcat((char *)buf,radiostat1);
	    strcat((char *)buf,(">Lounge mode\r\n"));
 	    strcat((char *)buf,("</strong><p>\r\n"));
	    strcat((char *)buf,("<input type=\"submit\">\r\n"));
	    strcat((char *)buf,("</form></span></body></html>\r\n"));            /* Now Send the HTTP Remaining Response */
	    if (send(sockreg,buf,strlen((char *)buf)) <= 0)
                break;


                    } /* Disconnect the socket */
                    disconnect(sockreg);
                } else
                    Delayms(1); /* Wait for request */
                break;

            case SOCK_FIN_WAIT:
            case SOCK_CLOSING:
            case SOCK_TIME_WAIT:
            case SOCK_CLOSE_WAIT:
            case SOCK_LAST_ACK:
                /* Force to close the socket */
                close(sockreg);

                break;
        }
    }
    return 0;
}
Ejemplo n.º 16
0
void main(void){
//==============================================================================
// Main Program
// 
// Description: This function contains the while loop that runs continuously
// to act for the operating system. It also calls all the functions to
// initialize the system.
//
// Passed : no variables passed
// Locals: no variables declared
// Returned: no values returned
// Globals:     volatile unsigned int Time_Sequence;
//              volatile char one_time;
//              char* display_1
//              char* display_2
//              char* display_3
//              char* display_4
//              slow_input_down
//              control_state[CNTL_STATE_INDEX]
//              char big
//              char size_count;
//              char posL1
//              char posL2
//              char posL3
//              char posL4
//
// Author: David Pryor
// Date: Feb 2016
// Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1)
//==============================================================================
  Init_Ports();                             // Initialize Ports
  Init_Clocks();                            // Initialize Clock System 
  Init_Conditions();
  Time_Sequence = SWITCH_OFF;               // 
  Init_Timers();                            // Initialize Timers
  Init_LEDs();                              // Initialize LEDs
  Init_LCD();                               // Initialize LCD
  

//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
 while(ALWAYS) {                            // Can the Operating system run
   if(do_this == TRUE){
      Five_msec_Delay(FOR_ONE_SECOND);                     //pause
      display_2 = "FORWARD";                    //change display
      posL2 = LINE_POS_1;
      Display_Process();                        //push display
      straight_line();                          //forward
      
      Five_msec_Delay(FOR_ONE_SECOND);                     //pause
      display_2 = "REVERSE";                    //change display
      posL2 = LINE_POS_1;
      Display_Process();                        //push display
      straight_line_reverse();                  //reverse
      
      Five_msec_Delay(FOR_ONE_SECOND);
      display_2 = "FORWARD";                    //change display
      posL2 = LINE_POS_1;
      Display_Process();                        //push display
      straight_line();                          //forward
      
      Five_msec_Delay(FOR_ONE_SECOND);
      display_2 = "CW-SPIN";                   //change display
      posL2 = LINE_POS_1;
      Display_Process();                         //push display
      clockwise_spin();                          //forward
      
      Five_msec_Delay(FOR_ONE_SECOND);
      display_2 = "CCW-SPIN";                   //change display
      posL2 = LINE_POS_1;
      Display_Process();                         //push display
      counterclockwise_spin();                          //forward
      
      Five_msec_Delay(FOR_ONE_SECOND);                     //pause
      display_2 = "";                           //clear display
      posL2 = LINE_POS_1;
      Display_Process();                        //push display
      do_this = FALSE;
   }
 }
//------------------------------------------------------------------------------
}
Ejemplo n.º 17
0
 int main(void){
volatile unsigned char d;
volatile unsigned int i, j[20], x[5], temp[3]; // volatile to prevent optimization
volatile unsigned int a, b, c, e;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

P2DIR |= 0x02; // Set P1.0 to output direction

Init_UART();
Init_LCD();

j[0] = 0x5F;
j[1] = 0X06;
j[2] = 0X6B;
j[3] = 0X2F;
j[4] = 0X36;
j[5] = 0X3D;
j[6] = 0X7D;
j[7] = 0X07;
j[8] = 0X7F;
j[9] = 0X37;
j[10] = 0X77;
j[11] = 0X7C;
j[12] = 0X68;
j[13] = 0X6E;
j[14] = 0X79;
j[15] = 0X71;



for (;;){

//letter input 1
				a=INCHAR_UART();
				OUTA_UART(a);

//Check if it's a digit or a character and transform to binary
				if((a>=0x30) && (a<=0x39)){
					a = a-0x30;
				}
				else{
					a = a-0x37;
				}

//letter input 2
				b=INCHAR_UART();
				OUTA_UART(b);


//Check if it's a digit or a character and transform to binary
				if((b>=0x30) && (b<=0x39)){
					b = b-0x30;
				}
				else{
					b = b-0x37;
				}


//Multiply a by 16 because of Hex, add together to obtain final number
				temp[1] = (a*16)+(b);
	
				d=INCHAR_UART();
				OUTA_UART(d);

//letter input 3
				a=INCHAR_UART();
				OUTA_UART(a);
//letter input 4
				b=INCHAR_UART();
				OUTA_UART(b);
				OUTA_UART(0x3D);


//Repeat procedure for the next two characters
				if((a>=0x30) && (a<=0x39)){
					a = a-0x30;
					}
				else{
					a = a-0x37;
				}

				if((b>=0x30) && (b<=0x39)){
					b = b-0x30;
				}
				else{
					b = b-0x37;
				}


//Multiply a by 16 because of Hex, add together to obtain final number
				temp[2] = (a*16)+(b);

//Multiply
				e = temp[1]*temp[2];

//The next few steps will be used to display our output
				x[4] = e/4096;
				temp[0]=e%4096;

				x[3]=temp[0]/256;
				temp[0]=temp[0]%256;

				x[2]=temp[0]/16;
				temp[0]=temp[0]%16;

				x[1]= temp[0];

//Print on LCD
				LCDSeg[3] = j[x[4]];
				LCDSeg[2] = j[x[3]];
				LCDSeg[1] = j[x[2]];
				LCDSeg[0] = j[x[1]];

//Convert our decimal characters back to ascii
				if(x[4]<=9)
					x[4]=x[4] + 0x30;
				else
					x[4]=x[4] + 0x37;

				if(x[3]<=9)
					x[3]=x[3] + 0x30;
				else
					x[3]=x[3] + 0x37;

				if(x[2]<=9)
					x[2]=x[2] + 0x30;
				else
					x[2]=x[2] + 0x37;

				if(x[1]<=9)
					x[1]=x[1] + 0x30;
				else
					x[1]=x[1] + 0x37;


//print the characters onto the Hyperterminal
				OUTA_UART(x[4]);
				OUTA_UART(x[3]);
				OUTA_UART(x[2]);
				OUTA_UART(x[1]);
//Print New line
				OUTA_UART(0X0A);
				OUTA_UART(0X0D);


}
}
Ejemplo n.º 18
0
//---------------------------------------------------------------------------------------------------------
// Main Function                                                           
//---------------------------------------------------------------------------------------------------------
INT32 main()
{
										
	SYSCLK_INITIATE();				// Configure CPU clock source and operation clock frequency.
									// The configuration functions are in "SysClkConfig.h"
	
	CLK_EnableLDO(CLK_LDOSEL_3_3V);	// Enable ISD9100 interl 3.3 LDO.

	if (! SPIFlash_Initiate())		// Initiate SPI interface and checking flows for accessing SPI flash.
		while(1); 					// loop here for easy debug

	OUTPUTPIN_INITIATE();			// Initiate output pin configuration.
									// The output pins configurations are defined in "ConfigIO.h".
	
	KEYPAD_INITIATE();				// Initiate keypad configurations including direct trigger key and matrix key
									// The keypad configurations are defined in "ConfigIO.h".
	
	ULTRAIO_INITIATE();				// Initiate ultraio output configurations.
									// The ultraio output pin configurations are defined in "ConfigUltraIO.h"
	
	PDMA_INITIATE();				// Initiate PDMA.
									// After initiation, the PDMA engine clock NVIC are enabled.
									// Use PdmaCtrl_Open() to set PDMA service channel for desired IP.
									// Use PdmaCtrl_Start() to trigger PDMA operation.
									// Reference "PdmaCtrl.h" for PDMA related APIs.
									// PDMA_INITIATE() must be call before SPK_INITIATE() and MIC_INITIATE(), if open MIC or speaker.
	
	SPK_INITIATE();					// Initiate speaker including pop-sound canceling.
									// After initiation, the APU is paused.
									// Use SPK_Resume(0) to start APU operation.
									// Reference "MicSpk.h" for speaker related APIs.

	MIC_INITIATE();					// Initiate MIC.
									// After initiation, the ADC is paused.
									// Use ADC_Resume() to start ADC operation.
									// Reference "MicSpk.h" for MIC related APIs.
	
																	
	App_Initiate();					// Initiate application for audio decode.

	i2c_Init(); //need to excute  before #define I2C_IRQ

#ifdef I2C_IRQ
	I2C_EnableInt(I2C0);
	NVIC_EnableIRQ(I2C0_IRQn);
	NVIC_SetPriority(I2C0_IRQn, 0);
#endif
#ifdef OLED_ENABLE
	Init_LCD();
	clear_LCD();

	print_Line(0, "OscarNuLiteExEnc");
//	print_Line(1, "2015.11.12      ");
//	print_Line(2, "Eric Yang      ");
//	print_Line(3, "0.96 OLED 128x64");
#endif

	while (1)
	{
		if ( g_u8AppCtrl&APPCTRL_RECORD )
		{
			if ( App_ProcessRec() == FALSE )
			{
				App_StopRec();
				#ifdef OLED_ENABLE
				print_Line(1, "   REC  Stop  ");	
				#endif
			}
		}
		else if ( g_u8AppCtrl&APPCTRL_PLAY )
		{
			if ( App_ProcessPlay() == FALSE )
			{
				App_StopPlay();
				#ifdef OLED_ENABLE
				print_Line(1, "   PLAY  Stop  ");	
				#endif
			}
		}

		TRIGGER_KEY_CHECK();		// Check and execute direct trigger key actions defined in "InputKeyActions.c"
									// Default trigger key handler is "Default_KeyHandler()"
									// The trigger key configurations are defined in "ConfigIO.h".
		
		MATRIX_KEY_CHECK();			// Check and execute matrix key actions defined in "InputKeyActions.c"
									// Default matrix key handler is "Default_KeyHandler()"
									// The matrix key configurations are defined in "ConfigIO.h".

		TOUCH_KEY_CHECK();        // Check and execute touch key actions defined in "InputKeyActions.c"
									// Default touch key handler is "Default_KeyHandler()"
									// The touch key configurations are defined in "ConfigIO.h".
	}
}
Ejemplo n.º 19
0
void main(void){
//==============================================================================
// Main Program
// 
// Description: This function contains the while loop that runs continuously
// to act for the operating system. It also calls all the functions to
// initialize the system.
//
// Passed : no variables passed
// Locals: no variables declared
// Returned: no values returned
// Globals:     volatile unsigned int Time_Sequence;
//              volatile char one_time;
//              char* display_1
//              char* display_2
//              char* display_3
//              char* display_4
//              slow_input_down
//              control_state[CNTL_STATE_INDEX]
//              char big
//              char size_count;
//              char posL1
//              char posL2
//              char posL3
//              char posL4
//
// Author: David Pryor
// Date: Feb 2016
// Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1)
//==============================================================================
  Init_Ports();                             // Initialize Ports
  Init_Clocks();                            // Initialize Clock System 
  Init_Conditions();
  Time_Sequence = SWITCH_OFF;               // 
  Init_Timers();                            // Initialize Timers
  Init_LEDs();                              // Initialize LEDs
  Init_LCD();                               // Initialize LCD
  Init_ADC();                               // Initialize ADC
  Init_Serial_UCA1(0);                      // BAUD rate 9600
  Init_Serial_UCA0(1);                      // BAUD rate 9600
  Five_msec_Delay(1);
  PJOUT |= IOT_STA_MINIAP; //turning on miniap (only works this way)
  IR_LED_OFF();
  lcd_BIG_mid();
  display_1 = "  David   ";
  display_2 = "Project  8";  
  display_3 = "  Pryor   ";
  display_4 = "";
  Display_Process();



//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
  while(ALWAYS) {                            // Can the Operating system run
    
    ADC_Process();              // call sampling function
    if(MainFG){
        Menu_Process();
    }
    else if(BaudMenuFG==TRUE){
        Baud_Menu(); 
    }
    else if(IOTMenuFG==TRUE){
        IOT_Menu();
    }
    
    if(StartCommandFG){ //StartCommandFG is true once "." has been received
        commandTree();
    }
    printMacAddress(); //prints mac address to screen
    macFG=FALSE; //turn off command to print mac address
    clearReceiveBuffer();
    parseIOTData();
  }
//------------------------------------------------------------------------------
}
Ejemplo n.º 20
0
int main(void){
volatile unsigned char a, b;
volatile unsigned int i, j[20], x; // volatile to prevent optimization

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

P2DIR |= 0x02; // Set P1.0 to output direction

Init_UART();
Init_LCD();

j[0] = 0x5F;
j[1] = 0X06;
j[2] = 0X6B;
j[3] = 0X2F;
j[4] = 0X36;
j[5] = 0X3D;
j[6] = 0X7D;
j[7] = 0X07;
j[8] = 0X7F;
j[9] = 0X37;
j[10] = 0X77;
j[11] = 0X7C;
j[12] = 0X68;
j[13] = 0X6E;
j[14] = 0X79;
j[15] = 0X71;


//Run indefinitely
for (;;){

				//letter input 1
				a=INCHAR_UART();
				OUTA_UART(a);

				//Check if input is digit or character and print
				//onto the board's LCD screen
				if(isdigit(a)){
					a = a - 0x30;
					LCDSeg[1]=j[a];
				}
				else{
					a = a - 0x37;
					LCDSeg[1]= j[a];
				}
				//letter input 2
				b=INCHAR_UART();
				OUTA_UART(b);
				
				//Repeat procedure followed for input a
				if(isdigit(b)){
					b = b - 0x30;
					LCDSeg[0]=j[b];
				}
				else{
					b = b - 0x37;
					LCDSeg[0]= j[b];
				}

				Print New line
				OUTA_UART(0X0A);
				OUTA_UART(0X0D);

				
P2OUT ^= 0x02; // Toggle P1.0 using exclusive-OR
i = 10000; // SW Delay
do i--;
while (i != 0);
}
}
Ejemplo n.º 21
0
 int main(void){
volatile unsigned char d;
volatile unsigned int i, j[20], x[5], temp[3]; // volatile to prevent optimization
volatile unsigned int a, b, c, e;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

P2DIR |= 0x02; // Set P1.0 to output direction

Init_UART();
Init_LCD();

j[0] = 0x5F;
j[1] = 0X06;
j[2] = 0X6B;
j[3] = 0X2F;
j[4] = 0X36;
j[5] = 0X3D;
j[6] = 0X7D;
j[7] = 0X07;
j[8] = 0X7F;
j[9] = 0X37;
j[10] = 0X77;
j[11] = 0X7C;
j[12] = 0X68;
j[13] = 0X6E;
j[14] = 0X79;
j[15] = 0X71;



for (;;){

//letter input 1
				a=INCHAR_UART();
				OUTA_UART(a);

//Check if it's a digit or a character and transform to binary
				if((a>=0x30) && (a<=0x39)){
					a = a-0x30;
				}
				else{
					a = a-0x37;
				}

//letter input 2
				b=INCHAR_UART();
				OUTA_UART(b);


//Check if it's a digit or a character and transform to binary
				if((b>=0x30) && (b<=0x39)){
					b = b-0x30;
				}
				else{
					b = b-0x37;
				}


//Multiply a by 16 because of Hex, add together to obtain final number
				temp[1] = (a*16)+(b);
	
				d=INCHAR_UART();
				OUTA_UART(d);

//letter input 3
				a=INCHAR_UART();
				OUTA_UART(a);
//letter input 4
				b=INCHAR_UART();
				OUTA_UART(b);
				OUTA_UART(0x3D);


//Repeat procedure for the next two characters
				if((a>=0x30) && (a<=0x39)){
					a = a-0x30;
					}
				else{
					a = a-0x37;
				}

				if((b>=0x30) && (b<=0x39)){
					b = b-0x30;
				}
				else{
					b = b-0x37;
				}


//Multiply a by 16 because of Hex, add together to obtain final number
				temp[2] = (a*16)+(b);
				
//If both numbers are equal
				if(temp[1]==temp[2]){
					e = 0;
					LCDSeg[2]=0x00;
				}


//If the first number is bigger simply subtract
				else if(temp[1]>temp[2]){
				e = temp[1]-temp[2];
				LCDSeg[2]=0x00; //reset LCD
				}
				
//If second number is bigger, invert numbers and add (-) before answer
				else{
					e=temp[2]-temp[1];
					OUTA_UART(0X2D);
					LCDSeg[2]=0x20;
				}

//The next three steps will yield the digits we'll print onto the LCD
				if((e/16)>15){
					x[3] =1;
					x[2]=(e/16)-16;
				}
				else{
					x[3]=0;
					x[2]=e/16;
				}

				x[1]= e%16;

//Print on LCD
				LCDSeg[1] = j[x[2]];
				LCDSeg[0] = j[x[1]];

//Convert our decimal characters back to ascii
				if(x[3]<=9)
					x[3]=x[3] + 0x30;
				else
					x[3]=x[3] + 0x37;

				if(x[2]<=9)
					x[2]=x[2] + 0x30;
				else
					x[2]=x[2] + 0x37;

				if(x[1]<=9)
					x[1]=x[1] + 0x30;
				else
					x[1]=x[1] + 0x37;


//print the characters onto the Hyperterminal
				OUTA_UART(x[2]);
				OUTA_UART(x[1]);
//Print New line
				OUTA_UART(0X0A);
				OUTA_UART(0X0D);


}
}
Ejemplo n.º 22
0
 ////////////////////////////////////////////////////////////////////////////
///////////////
// 函数名:
// 编写者:
// 参考资料:
// 功 能:
// 输入参数:
// 输出参数:
// 备 注:
////////////////////////////////////////////////////////////////////////////
///////////////
void main (void)
{	PCA0MD &= ~0x40;                    // Disable Watchdog timer
	Init_VAR();
	Init_Device();
	Init_patch();
	BUZZY_OFF();
	Init_sensor();
	P1MDOUT&=~0x06;	//p11 p12 非推挽	 LCD时钟数据和加密
	P1MDOUT&=~0x40;	//p16 非推挽	LCD选通
	P1MDOUT&=~0x80;	//p17 非推挽  LCD电源总开开关
	P1MDOUT&=~0x20;	//p15 非推挽	LCD选通
#ifdef	SECURE_SPI
	P0MDOUT&=~0x80;	//p07 非推挽   //加密MCLK
	P07=1;
#endif
	P0MDOUT&=~0x20;  //充满检测 ,高:充满或未冲  低:充电
	P1|=0x46;	  //srb clk data 
	PO_LCD_POWER(P_LCD_ON);
	Init_LCD();
	Init_EPROM();
#ifdef	SECURE_SPI
  {extern void InitSPICom(void) ;
	extern char TEST_SPI(char CMD_a);
	BYTE tryc=3;
	InitSPICom()  ;
	F_demo=1;
	do
	 {
		if(1==TEST_SPI(CMD_RD_ID))
		{	
		F_demo=0;
		break;
		}
		
		DelayXms(300);

	}while(tryc--)	 ;
	if(1==F_demo)
	{	
		
		DisplayCont=DISPLAY_DEMO;
		Display_All();	   //显示初始错误

	}

	}
	
#endif
	DPRINTF(printf("MAIN Program\n" ))	 ;
#if 0
	if(PI_ADJUST_DET())
	{
	  DelayXms(100);
	  if(PI_ADJUST_DET())	
	  NEW_KEY= KEY_ADJUST;
	  
	}
#endif
#if 1
	if(PWR_G2==0)
	{ 
	  	diaplay_std ();
	    DelayXms(3000);
	}
#endif
	while(1)
	{
		
	   {
//WORD i  ;extern 	  BYTE StateSensor	  ;
//     	if(StateSensor==-1)
//		LEDIO=!LEDIO;
		}
		if(F_5ms)
		{
		F_5ms=0;
	    if(PWR_G1==0)	{StateSensor=0;}
	{extern void TestACHOL();
		  TestACHOL();	
			
		}

		}
	//	if(F_10ms)
	//	{
	//		F_10ms=0;

	//	}
		if(F_50ms)
		{	F_50ms=0;
			
			Task_50ms();

			
			
		}
		if(F_100ms)
		{  
			F_100ms=0;
	/*		

		{extern void TestACHOL();
		  TestACHOL();	
			
		}
*/
		   {	
		    extern WORD CountHeat;	
		    if(CountHeat<=350)
			{
			  CountHeat++;
			} 
			}
			DO_Key_Action()	 ;
			Display_All();
			{
			extern void SendCycbuf(void);
			SendCycbuf();

			}
		    
			
		}
		if(F_200ms)
		{	 
			

			F_200ms=0; 
			
			
		}
		if(F_500ms)
		{	F_500ms=0;
			
			 
			
		}
		
		if(F_1000ms)
		{
		//	DPRINTF(printf("time=%bd \n" ,sys_time.Time_1_sec))	 ;
		 Task_500ms();
		}
		
		
	}
	
}