From ccae95273ad0eb649c7ec2bd1e9df326e3a3f74d Mon Sep 17 00:00:00 2001 From: zayn121381 <62085161+zayn121381@users.noreply.github.com> Date: Sun, 8 Jan 2023 13:50:38 -0800 Subject: [PATCH] Add files via upload --- ADS1115_driver/main.c | 120 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 ADS1115_driver/main.c diff --git a/ADS1115_driver/main.c b/ADS1115_driver/main.c new file mode 100644 index 0000000..2b0da5a --- /dev/null +++ b/ADS1115_driver/main.c @@ -0,0 +1,120 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:megaatmega2560] +platform = atmelavr +board = megaatmega2560 +framework = arduino + +#include "led.h" +#include "delay.h" +#include "sys.h" +#include "usart.h" +#include "lcd.h" +#include "key.h" +#include "ads1115.h" + +float aa; + + int main(void) + { + float t1; + u16 t,result; + u8 key; + u16 i=0; + + NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// Set interrupt priority group 2 + delay_init(); + uart_init(9600); // The serial port is initialized to 9600 + LED_Init(); + //LCD_Init(); + KEY_Init(); + //IIC初始化 + ADS1115_Init(); + + while(1) + { + key=KEY_Scan(0); + if(key==WKUP_PRES) + { + result=lvbo(0xeb,0x82); // A0 A1 is the differential input test terminal, low eight bits + high eight bits 1111 1011, 1000 0010 + + if(result >= 0x8000 && result <= 0xffff) + result = 0xffff - result; //If the difference is negative, take the absolute value, so that A0 and A1 can be connected positively and negatively. + else if(result >= 0xffff) + result = 0; + + t1=4.096*2*result/65535; //converted to voltage + + printf("The range is 4.096V, the voltage between A0-A1 = %f V\r\n",t1);//print + + if(result == 0x7fff || result == 0x8000) + { + printf("over range \r\n\r\n"); + } + else + { + printf("Read OK \r\n\r\n"); + } + } + + if(key==KEY0_PRES) + { + result=lvbo(0xe3,0xb2); //A2 A3 is the differential input test terminal, low eight bits + high eight bits 1111 0011,1011 0010 + + + if(result >= 0x8000) + result = 0xffff - result; //If the difference is negative, take the absolute value, so that A2 and A3 can be connected positively and negatively. + + + t1=4.096*2*result/65535; //converted to voltage + + printf("The range is 4.096V, the voltage between A2-A3 = %f V\r\n",t1); //print + + if(result == 0x7fff || result == 0x8000) // exceeds the maximum value or falls below the minimum value + { + printf("over range \r\n\r\n"); + } + else + { + printf("over range\r\n\r\n"); + } + } + + if(key == KEY1_PRES) + { + result=lvbo(0xe3,0xb4); //A2 A3 is the differential input test terminal, low eight bits + high eight bits 1111 0011,1011 0100 + + if((result >= 0x8000) && (result <= 0xffff)) + result = 0xffff - result; //If the difference is negative, take the absolute value, so that A0 and A1 can be connected positively and negatively. + else if(result >= 0xffff) + result = 0; + t1=2.048*2*result/65535; //converted to voltage + + printf("The range is 2.048V, the voltage between A0-A1 = %f V\r\n",t1);//打印 + if(result == 0x7fff || result == 0x8000) + { + printf("over range \r\n\r\n"); + } + else + { + printf("over range \r\n\r\n"); + } + } + + i++; + delay_ms(10); + if(i==20) + { + LED0=!LED0;//Prompt system is running + i=0; + } + } +}