コード例 #1
0
/***************************************************EEPROM*****************************************
 				Writes and Reads a character to and from EEPROM
*****************************************************TEST*****************************************/
void eeprom_test()
{
	 unsigned char eeprom_address=0x00, write_char = 'X', read_char;
	 
	UART_Printf("Connections SCL->P0.6 SDA->P0.7");
	UART_Printf("Make connections and hit 'k' to test! ");
        while(UART_RxChar()!='k');
	 UART_TxString("\n\rEeprom Write: ");      //Print the message on UART
	 UART_TxChar(write_char);			         //Print the char to be written 
	 EEPROM_WriteByte(eeprom_address,write_char);	// Write the data at memoryLocation	0x00

	 UART_TxString("  Eeprom Read: ");            //Print the message on UART
	 read_char = EEPROM_ReadByte(eeprom_address);	// Read the data from memoryLocation 0x00
	 UART_TxChar(read_char);	
}
コード例 #2
0
/* start the main program */
void main() 
{
   unsigned char sec,min,hour,day,month,year;

  /* Initilize the Uart before Transmiting/Reaceiving any data */
    UART_Init(9600);

  /* Initilize the RTC(ds1307) before reading or writing time/date */
    RTC_Init();

	UART_TxString(" Testing RTC ");
 /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015



   /* Display the Time and Date continuously */ 
   while(1)
    {
	   /* Read the Time from RTC(ds1307) */ 
        RTC_GetTime(&hour,&min,&sec);      
		
	    /* Read the Date from RTC(ds1307) */ 
        RTC_GetDate(&day,&month,&year);        
	 
        UART_Printf("\n\r the time is :%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
	  }		

  }
コード例 #3
0
void seg_test()
{  
 unsigned char seg_code[]={0xC0,0xF9,0xA4,0xB0}; 
 UART_TxString("\n\r Segment DataBus: PORTD    Seg select: S1->PB.0 S2->PB.1 S3->PB.2 S4->PB.3");
 UART_Printf("\n\rMake connections and hit 'k' to test! ");
 while(UART_RxChar()!='k');
 SegValueDirnReg = C_PortOutput_U8;
 SegSelectDirnReg = C_PortOutput_U8;

	while(1)
	{  
	   SegmentSlection=SegOne;
	   SegmentValue = seg_code[0];
	   DELAY_us(10); 
	   SegmentSlection=SegTwo;
	   SegmentValue = seg_code[1];
	   DELAY_us(10);
	   SegmentSlection=SegThree;
	   SegmentValue = seg_code[2];
	   DELAY_us(10);	
	   SegmentSlection=SegFour;  
	   SegmentValue = seg_code[3];
	   DELAY_us(10);
	 }  
}
コード例 #4
0
void LCD_test()
{     
          UART_TxString("\n\r LCD DataBus: P2 Control: RS-P0.0 RW-P0.1 E-P0.2 ");
	  UART_Printf("\n\r Make connections and hit 'k' to test ");
	  while(UART_RxChar()!='k');
	  LCD_Init(8,2,16);
	  DELAY_ms(100);
	  LCD_DisplayString("Explore Embedded!");
	  while(1);
}
コード例 #5
0
/* start the main program */
void main() 
{
   UART_Init(9600);
   UART_TxString("\n\rTest menu Utra x51 v1.1\r\n 1:GPIO Blink\r\n 2:LCD \n\r 3:7-Segment\n\r 4:RTC\n\r 5:EEPROM\n\r 6:ADC\n\r 7:Keypad \n\r Enter option:");
   UART_TxString("\n\rReset the board after test is done");
   mm_option = UART_RxChar();
   while(1)
    {
 	  	switch(mm_option)
		{
		 case '1': gpio_test(); break;
		 case '2': LCD_test(); break;
		 case '3': seg_test(); break;
		 case '4': rtc_test(); break; 
		 case '5': eeprom_test(); break; //eeprom
		 case '6': adc_test(); break;
		 case '7': keypad_test();break;
		 default:break;
		}
	}
}
コード例 #6
0
ファイル: main.c プロジェクト: Amritach/Code-Libraries
/* start the main program */
void main() 
{
  unsigned char eeprom_address=0x00, write_String[] = {"hello world"}, read_string[15];

  /* Initilize the Uart before Transmiting/Reaceiving any data */
    UART_Init(9600);												  
 
   while(1)
    {
	   	   UART_TxString("\n\rWr:");                      //Print the message on UART
		   UART_TxString(write_String);			         //Print the String to be written 
		   EEPROM_WriteString(eeprom_address,write_String); // Write the String at memory Location	0x00

		   
		   UART_TxString("  Rd:");                           //Print the message on UART
		   EEPROM_ReadString(eeprom_address,read_string);	// Read the String from memory Location 0x00
		   UART_TxString(read_string);			            //Print the read String

	  }		

  }
コード例 #7
0
void LCD_4bit_test()
{
     UART_TxString("\n\r LCD DataBus:(PD4-PD7)  RS-PB.0  RW-PB.1  EN-PB.2 ");
      UART_Printf("\n\r Make connections and hit 'k' to test ");
      while(UART_RxChar()!='k');
      LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PD_4,PD_5,PD_6,PD_7);
      LCD_Init(2,16);
      DELAY_ms(100);
      LCD_DisplayString("Explore Embedded");
      LCD_DisplayString("Lcd 4-bit Mode");
      while(1);
}
コード例 #8
0
/* start the main program */
void main() 
{
   UART_Init(9600);
   UART_TxString("\n\rPIC Ultra baord menu v2.0\r\n 1:GPIO Blink\r\n 2:LCD 8-bit \n\r 3:LCD 4-bit\n\r 4:7-Segment\n\r 5:RTC\n\r 6:EEPROM\n\r 7:ADC\n\r 8:Keypad \n\r Enter option:");
   UART_TxString("\n\rReset the board after test is done");
   mm_option = UART_RxChar();
   while(1)
    {
 	  	switch(mm_option)
		{
		 case '1': gpio_test(); break;
		 case '2': LCD_8bit_test(); break;
		 case '3': LCD_4bit_test(); break;
		 case '4': seg_test(); break;
		 case '5': rtc_test(); break;
		 case '6': eeprom_test(); break; //eeprom
		 case '7': adc_test(); break;
		 case '8': keypad_test();break;
		 default:break;
		}
	}
}
コード例 #9
0
ファイル: cmd.c プロジェクト: jdeguire/pjcontroller
/* Run one iteration of the interface state machine.  This is responsible for displaying the command
 * prompt, receiving characters, and running the resulting command by searching for and calling the
 * proper command function.  Call this in your main loop.
 */
void Cmd_ProcessInterface()
{
	switch(m_cmdstate)
	{
		case eCmd_Prompt:
			if(UART_TxAvailable() >= 4)
			{
				UART_TxData("\r#> ", 4);
				m_cmdlen = 0;
				++m_cmdstate;
			}
			break;
		case eCmd_Receive:			
		{
			uint16_t avail = UART_RxAvailable();

			while(avail--)
			{
				char c = UART_RxChar();
				wdt_reset();

				if(0x08 == c)           // backspace -- remove last character
				{
					if(m_cmdlen > 0)
						--m_cmdlen;
				}
				else if(0x1B == c)      // escape -- clear prompt
				{
					m_cmdstate = eCmd_Prompt;
					break;
				}
				else                    // add the character to the buffer
				{
					m_cmdbuf[m_cmdlen] = c;
					++m_cmdlen;

					// either got a command or buffer is full
					if(c == '\r'  ||  m_cmdlen >= CMD_BUFSIZE)
					{
						m_cmdbuf[m_cmdlen] = 0;   // terminate command
						++m_cmdstate;
						break;
					}
				}
			}

			wdt_reset();
		}
		break;
		case eCmd_Run:
			m_cmdstate = eCmd_Prompt;

			if(m_numcmds > 0)
			{
				uint8_t i;

				// look for the right command and call its function
				for(i = 0; i < m_numcmds; ++i)
				{
					size_t len = strlen(m_cmds[i].name);

					if(0 == strncmp(m_cmds[i].name, m_cmdbuf, len)  &&
					   (m_cmdbuf[len] == ' '  ||  m_cmdbuf[len] == '\r'))
					{
						m_cmds[i].cmdfunc(m_cmdbuf, m_cmdlen);
						break;
					}
				}

				// didn't find the command
				if(i == m_numcmds)
					UART_TxData_P(PSTR("Unknown command\r"), 16);
			}
			break;
		case eCmd_Help:
			if(m_helpindex < m_numcmds)
			{
				size_t txlen = (strlen(m_cmds[m_helpindex].name) + 
								strlen_P(m_cmds[m_helpindex].help) + 5);

				if(txlen > UART_TX_BUFSIZE)
					txlen = UART_TX_BUFSIZE;

				if(UART_TxAvailable() >= txlen)
				{
					UART_TxString(m_cmds[m_helpindex].name);
					UART_TxData("\t - ", 4);
					UART_TxString_P(m_cmds[m_helpindex].help);
					UART_TxChar('\r');

					++m_helpindex;
				}
			}
			else
			{
				m_cmdstate = eCmd_Prompt;
				m_helpindex = 0;
			}
			break;
		default:
			m_cmdstate = eCmd_Prompt;
			break;
	}
}
コード例 #10
0
void UART_Printf(uint8_t var_uartChannel_u8, const char *argList, ...)
{
    const char *ptr;
    double var_floatNum_f32;
    va_list argp;
    sint16_t var_num_s16;
    sint32_t var_num_s32;
    uint16_t var_num_u16;
    uint32_t var_num_u32;
    char *str;
    char  ch;
    uint8_t var_numOfDigitsToTransmit_u8;

    va_start(argp, argList);

    /* Loop through the list to extract all the input arguments */
    for(ptr = argList; *ptr != '\0'; ptr++)
    {

        ch= *ptr;
        if(ch == '%')         /*Check for '%' as there will be format specifier after it */
        {
            ptr++;
            ch = *ptr;
            if((ch>=0x30) && (ch<=0x39))
            {
                var_numOfDigitsToTransmit_u8 = 0;
                while((ch>=0x30) && (ch<=0x39))
                {
                    var_numOfDigitsToTransmit_u8 = (var_numOfDigitsToTransmit_u8 * 10) + (ch-0x30);
                    ptr++;
                    ch = *ptr;
                }
            }
            else
            {
                var_numOfDigitsToTransmit_u8 = C_MaxDigitsToTransmitUsingPrintf_U8;
            }                


            switch(ch)       /* Decode the type of the argument */
            {

            case 'C':
            case 'c':     /* Argument type is of char, hence read char data from the argp */
                ch = va_arg(argp, int);
                UART_TxChar(var_uartChannel_u8,ch);
                break;



            case 'd':    /* Argument type is of signed integer, hence read 16bit data from the argp */
                var_num_s16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)
                if(var_num_s16<0)
                { /* If the number is -ve then display the 2's complement along with '-' sign */ 
                    var_num_s16 = -var_num_s16;
                    UART_TxChar(var_uartChannel_u8,'-');
                }
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_s16,var_numOfDigitsToTransmit_u8);
#endif
                break;



            case 'D':    /* Argument type is of integer, hence read 16bit data from the argp */
                var_num_s32 = va_arg(argp, sint32_t);
#if (Enable_UART_TxNumber == 1)                
                if(var_num_s32<0)
                { /* If the number is -ve then display the 2's complement along with '-' sign */
                    var_num_s32 = -var_num_s32;
                    UART_TxChar(var_uartChannel_u8,'-');
                }
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_s32,var_numOfDigitsToTransmit_u8);
#endif                
                break;    



            case 'u':    /* Argument type is of unsigned integer, hence read 16bit unsigned data */
                var_num_u16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)                
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_u16,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'U':    /* Argument type is of integer, hence read 32bit unsigend data */
                var_num_u32 = va_arg(argp, uint32_t);
#if (Enable_UART_TxNumber == 1)                
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_u32,var_numOfDigitsToTransmit_u8);
#endif                
                break;            


            case 'x':  /* Argument type is of hex, hence hexadecimal data from the argp */
                var_num_u16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)                
                UART_TxNumber(var_uartChannel_u8,C_HEX_U8, var_num_u16,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'X':  /* Argument type is of hex, hence hexadecimal data from the argp */
                var_num_u32 = va_arg(argp, uint32_t);
#if (Enable_UART_TxNumber == 1)                        
                UART_TxNumber(var_uartChannel_u8,C_HEX_U8, var_num_u32,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'b':  /* Argument type is of binary,Read int and convert to binary */
                var_num_u16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)                        
                if(var_numOfDigitsToTransmit_u8 == C_MaxDigitsToTransmitUsingPrintf_U8)
                {
                    var_numOfDigitsToTransmit_u8 = 16;
                }
                UART_TxNumber(var_uartChannel_u8,C_BINARY_U8, var_num_u16,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'B':  /* Argument type is of binary,Read int and convert to binary */
                var_num_u32 = va_arg(argp, uint32_t);
#if (Enable_UART_TxNumber == 1)                
                if(var_numOfDigitsToTransmit_u8 == C_MaxDigitsToTransmitUsingPrintf_U8)
                    var_numOfDigitsToTransmit_u8 = 16;                
                UART_TxNumber(var_uartChannel_u8,C_BINARY_U8, var_num_u32,var_numOfDigitsToTransmit_u8);    
#endif                
                break;



            case 'F':
            case 'f': /* Argument type is of float, hence read double data from the argp */
                var_floatNum_f32 = va_arg(argp, double);
#if (Enable_UART_TxFloatNumber == 1)                
                UART_TxFloatNumber(var_uartChannel_u8,var_floatNum_f32);
#endif
                break;



            case 'S':
            case 's': /* Argument type is of string, hence get the pointer to sting passed */
                str = va_arg(argp, char *);
                UART_TxString(var_uartChannel_u8,str);                
                break;



            case '%':
                UART_TxChar(var_uartChannel_u8,'%');
                break;
            }
        }
        else
        {