[iOSGithub] Suspear/Suspending button/auxiliary button (similar to the ASSISTIVETOUCH/JD/Jacking of JD/Getting/Costs/Costs/Costume/Costume/Capital)

2022-12-24   ES  

1. Experimental purpose

Send the collected internal temperature sensor information to the upper machine through the serial port

2. Experimental process

1, register configuration

ADCCON1(0XB4)
adc control register 1
bit7: EOC ADC end the logo position
0: AD conversion is performed 1: AD conversion is completed
  bit6: ST manually start AD conversion
0: Close 1: Start AD conversion (need BIT5: BIT4 = 11)
  BIT5: BIT4 AD conversion start method
00: external trigger
01: Convert full speed, no need to trigger
10: T1 channel is triggered
11: Manual trigger
  BIT3: BIT2 16 -bit random number generator control bit
00: normal mode (13x open)
01: Open the LFSR clock once (13x open)
10: Reserve
11:
ADCC0N2(0XB5)
Sequence AD conversion control register 2
Bit7: Bit6 Sref Select AD conversion reference voltage
00: Internal reference voltage (1.25V)
01: External reference voltage Ain7 input
10: Simulation power voltage
11: External reference voltage AIN6-AIN7 Differential input
  BIT5: BIT4 Set AD conversion resolution
00: 64DEC, 7 digits are valid
01: 128DEC, 9 -bit effective,
10: 256DEC, 10 -bit effective
11: 512DEC, 12 -bit valid
  BIT3:BIT2:BIT1:BIT0
Set the last channel of AD conversion. If the ADC is running at the time, it will start immediately after completing the sequence AD conversion.
0000:AIN0
0001:AIN1
0010:AIN2
0011:AIN3
0100:AIN4
0101:AIN5
0110:AIN6
0111:AIN7
1000: Ain0-AIN1 Differential
1001: Ain2-AIN3 Differential
1010: Ain4-AIN5 Differential
1011: Ain6-AIN7 Differential
1100:GND
1101: Reserve
1110: Temperature sensor
1111: 1/3 Simulation power supply voltage
ADCCON3(0XB5)
Single channel AD conversion control register 3
Bit7: Bit6 Sref Select Single -channel AD Select Reference Voltage
00: Internal reference voltage (1.25V)
01: External reference voltage Ain7 input
10: Simulation power voltage
11: External reference voltage AIN6-AIN7 Differential input
  BIT5: BIT4 Set a single channel AD conversion resolution
00: 64DEC, 7 digits are valid
01: 128DEC, 9 -bit effective,
10: 256DEC, 10 digits are valid
11: 512DEC, 12 -bit valid
  BIT3:BIT2:BIT1:BIT0
Set AD conversion at the end channel. If the ADC is running at the time, it will start immediately after completing the sequence AD conversion.
0000:AIN0
0001:AIN1
0010:AIN2
0011:AIN3
0100:AIN4
0101:AIN5
0110:AIN6
0111:AIN7
1000: Ain0-AIN1 Differential
1001: Ain2-AIN3 Differential
1010: Ain4-AIN5 Differential
1011: Ain6-AIN7 Differential
1100:GND
1101: Reserve
1110: Temperature passenger
1111: 1/3 Simulation power supply voltage
TR0(0x624B) BIT0: Set 1 means connecting the temperature sensor with ADC
ATEST(0x61BD) BIT0: Place 1 indicates that the temperature sensor is enabled

2, source code

adc.h

#ifndef ADC_H_
#define ADC_H_

#include <ioCC2540.h>

#define uint unsigned int
#define uchar unsigned char

void AdcInit(void);//Internal temperature sensor

uint GetAdcValue(void);//Get a single conversion AD value

uint TempDeal(uint TempAdValue);//The AD value of the temperature sensor is converted to temperature value, and it expands 100 times

void ChanceValueToString(uint Data ,uchar *Buff);//Convert the numerical value to a string





#endif
#include "adc.h"


void AdcInit(void)//Internal temperature sensor
{
  ADCCON1 = 0x33;//Software startup conversion
  ADCCON3 = 0x3e;//Internal reference voltage, 12 -bit resolution, select the temperature sensor input
  TR0 = 0x01;
  ATEST = 0x01;
//  ADCCON1 |= 0x40;//Software startup conversion
}

uint GetAdcValue(void)
{
  uint AdValue=0;
  
  ADCCON1 |= 0x40;
  while(!(ADCCON1 & 0x80));
  AdValue = ADCL >>4;
  AdValue |= ADCH <<4;
  
  return AdValue; 
}

uint TempDeal(uint TempAdValue)//The AD value of the temperature sensor is converted to the temperature value, and the expansion of 100 times
{
  float Tempruture;
  Tempruture = (TempAdValue-1367.5)/4.5+2.5; 
  TempAdValue = (uint)(Tempruture*100);
  return TempAdValue;
}

void ChanceValueToString(uint Data ,uchar *Buff)//Convert the numerical value to a string
{
  Buff[0] = (Data/10000)+0x30; 
  Buff[1] = ((Data/1000)%10)+0x30; 
  Buff[2] = ((Data/100)%10)+0x30; 
  Buff[3] = '.'; 
  Buff[4] = ((Data/10)%10)+0x30; 
  Buff[5] = (Data%10)+0x30; 
  Buff[6] = '\n'; 
  Buff[7] = '\0';
}

sysclock

#ifndef SYSCLK_H_
#define SYSCLK_H_

#include<ioCC2540.h>

void SysClkSet_32M(void);//Set the system clock 32MHz

#endif
#include "sysclk.h"


void SysClkSet_32M(void)//Set the system clock 32MHz
{
  CLKCONCMD &= ~0x40;
  while(CLKCONSTA & 0x40);    
  CLKCONCMD &= ~0x47;  
}

usart0

#ifndef USART0_H_
#define USART0_H_

#include<ioCC2540.h>

#define uint unsigned int
#define uchar unsigned char


void UartInit(void);//115200

void Uart0_SendByte(uchar Byte);//Send a data

void Uart0_SendString(uchar *Buff);//Send a string



#endif
#include"usart0.h"

void UartInit(void)
{  
  P2DIR &= ~0xc0;//Backup location 1
  PERCFG &= ~0x01;//Set UART0 high priority
  P0SEL |= 0x3c;//2 3 4 5 as a peripheral
  U0CSR = 0xc0;
  U0GCR = 11;  //Set the baud rate, please refer to the corresponding table in the CC2530 Chinese documentation
  U0BAUD = 216; 
  EA=1;
  URX0IE=1;//Receive interrupt URX0IF-Receive the interrupt logo bit UTX0IF-Send the symbol position
}

void Uart0_SendByte(uchar Byte)//Send a character
{
  U0DBUF=Byte; 
  while(!UTX0IF);
  UTX0IF=0;
}

void Uart0_SendString(uchar *Buff)//Send a string of characters
{
  uchar *p;
  p=Buff;
  while(*p != 0)
  {
    Uart0_SendByte(*p);
    p++;
  }
}


#pragma vector = URX0_VECTOR   //Interrupt vector
__interrupt void Uart0RxInt(void)
{
  URX0IF=0; 
  Uart0_SendByte(U0DBUF);
}

mian

#include<ioCC2540.h>
#include"sysclk.h"
#include"usart0.h"
#include"adc.h"

#define uint unsigned int
#define uchar unsigned char
void Delay(uint n);
uchar TempDis[8];

void main()
{
  SysClkSet_32M();//Set the system clock 32MHz
  UartInit();     //115200
  
  while(1)
  {
    AdcInit();      //Initialize ADC
    ChanceValueToString(TempDeal(GetAdcValue()),TempDis);//Get the current temperature value and replace it into a string
    Uart0_SendString(TempDis);//Print temperature value
    Delay(1000);
  }
}



void Delay(uint n)
{
  uint i,j;
  for(i=n;i>0;i--)
    for(j=5000;j>0;j--);
}

Reprinted: https://www.cnblogs.com/bluemountain-haggendazs/p/4298381.html

source

Related Posts

MySQL uses mysqlbulkloader batch insertion

linux often uses GDB shortcuts to complete

seekbar is dragged, play the system ringtone at the same time to achieve the audition effect

HDLBITS -Verilog Learning Notes Fourier

[iOSGithub] Suspear/Suspending button/auxiliary button (similar to the ASSISTIVETOUCH/JD/Jacking of JD/Getting/Costs/Costs/Costume/Costume/Capital)

Random Posts

ROS (8): Keyboard control Smartcar

Pyecharts Draw Map (Geo and Map) (Rich details) Hello

Rails Read Notes Chapter 7

ubuntu network card ENP0S3 is changed to ETH0

Volley framework get post request