⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_ads7841.c

📁 P98v51RD2 source codes for all the peripherals
💻 C
字号:
#include <p89v51rd2.h>  
#include "../lcd/lcd.h"	
#include "ads7841.h"

#define NUMBER_OF_DIGITS 16

/*************** Convert long integer to ascii ************/
void _ultoa_(unsigned long value, char* string, unsigned char radix)
{
	unsigned char index;				// Counter of digit
	char buffer[NUMBER_OF_DIGITS]; 	// Data buffer
	 index = NUMBER_OF_DIGITS;		// Load counter by digit count

  	do 
  	{
    		buffer[--index] = '0' + (value % radix);	// Convert configuration by radix(10 or 16)
    		if ( buffer[index] > '9') buffer[index] += 'A' - '9' - 1;	// For base over 10(base 16)
   	 	value /= radix;		// Div by to calculate into next digit
  	} while (value != 0);		// End for convert?

  	do 
  	{
    		*string++ = buffer[index++];	// Load convert value to string buffer
  	} while ( index < NUMBER_OF_DIGITS );	// Over of digit count?

  	*string = 0;  	// Place null for end string
}

/*************** Convert long integer to ascii ************/
void _ltoa_(long value_l, char * string_l, unsigned char radix_l)
{
  	if (value_l < 0 && radix_l == 10) 	// For value < 0 (base 10)
  	{
    		*string_l++ = '-';		// Load sign '-' for display
    		_ultoa_(-value_l, string_l, radix_l);	// Convert long integer
	}
 	else 
 	{
    		_ultoa_(value_l, string_l, radix_l);	// Convert long integer
  	}
}

void PowerOn()
{
    unsigned char inner, outer;

    for (outer = 0x00; outer < 0x10; outer++) 
    {
        for (inner = 0x00; inner < 0xFF; inner++);
    }
    
    LCD_init();
    
    for (inner = 0; inner < 10; inner++) 
    	LCD_delay(2);
}

/***************************** Main Program **********************************/
void main()
{
	unsigned char i,j; 
	char buff[4];	
	
	PowerOn();	
	
	LCD_row1(); LCD_puts("Ch0:"); LCD_command(0x88); LCD_puts("Ch1:");	
	LCD_row2(); LCD_puts("Ch2:"); LCD_command(0xC8); LCD_puts("Ch3:"); 
	
	while(1)								
	{
		LCD_command(0x84); LCD_puts("    ");		/* Show analog channel 0 value */
		_ltoa_(analog(0), buff, 10);
		LCD_command(0x84); LCD_puts(buff);
		
		LCD_command(0x8C); LCD_puts("    ");		/* Show previous analog channel 1 value */
		_ltoa_(analog(1), buff, 10);
		LCD_command(0x8C); LCD_puts(buff);	
		
		LCD_command(0xC4); LCD_puts("    ");		/* Show previous analog channel 2 value */
		_ltoa_(analog(2), buff, 10);
		LCD_command(0xC4); LCD_puts(buff);
		
		LCD_command(0xCC); LCD_puts("    ");		/* Show previous analog channel 3 value */
		_ltoa_(analog(3), buff, 10);
		LCD_command(0xCC); LCD_puts(buff);

		for (i=0; i<0xFF ;i++ )
		   for (j=0; j<0xFF; j++);		/* Delay for a while */		
	
	}		
}   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -