/****************Pin Definition********************************
Interface: Hardware SPI
PB.1(SCK) SCLK Direction: 1
PB.2(MOSI) DIN Direction: 1
PB.3(MISO) DOUT Direction: 0
PB.4 CS Direction: 1
PB.5 EOC Direction: 0 DRRB="0x06"
MCU:ATmage128
AD:MAX1168(16bit)
Crystal:11.0592MWritten
by:Jesse Rei
**************************************************************/
#include
#include
#include"lcd.c"
#define uchar unsigned char
#define uint unsigned int
#define Command_H 0x01 //000 00 00 1 Channel 0, single channel conversion, no power saving mode, internal clock
#define Command_L 0x00 //The lower eight bits of the command are any number
#define CS_L PORTB&=~(1<<4) //PB.4
#define CS_H PORTB|=(1<<4)
#define READY PINB&0x20 //PB.5
fly tab[10]={'0','1','2','3','4','5','6','7','8','9'};
/**************Global variables********************************/
uchar buffer[5]={1,1,1,1,1};
uchar count="0";
uint sum="0";
/***************************************************/
/******************Port initialization***********************/
void port_init(void)
{
PORTA = 0xff;
DDRA = 0xff;
PORTB = 0x06;
DDRB = 0xff;
PORTC = 0x00; //m103 output on
DDRC = 0x00;
PORTD = 0xff;
DDRD = 0xff;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x00;
DDRG = 0x00;
}
/************************************************************/
/*************************SPI initialization*******************************/
void spi_init(void)
{
SPCR="0x5d"; //SPI enabled, host mode, high byte first, working mode 3, Fck/128
//SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0
// 0 1 0 1 1 0 1 1
SPSR = 0x00; //setup SPI, host frequency multiplication
}
/*************************************************************/
/*************************Start AD conversion***************************/
void start(uchar Com_H,uchar Com_L)
{
CS_L;
SPDR="Com"_H;
while(!(SPSR&(1<
while(!(SPSR&(1<
/************************************************************/
/******************Disassemble the number to display****************************/
void
{
uchar i;
for(i=0;i<=4;i++)
{
buffer[i]=a%10;
a=a/10;
}
}
/******************************************************************/
/*********************Disassemble the number to display****************************/
void getdata(void)
{
uchar
uint ad_data
uint ad_dat=0;
SPDR = 0xff; //Send data and provide pulse to max1168
while (!(SPSR &(1<
SPDR = 0xff; //Send data and provide pulses to max1168
while (!(SPSR &(1<
ad_ta
ad_dat=ad_ta
sum+=ad_dat; //Sixteen sampling results cumulative sum
count++;
if(count>15)
{
count="0";
ad_ta1
ad_ta2
ta_to_buffer
sum=0;
}
CS_H;
}
/**********************************************************/
/*************************延时1ms**************************
void delay1ms(uint t)
{
uint i;
for(;t>0;t--)
for(i=0;i<1106;i++)
;
}
**********************************************************/
/*************************主程序***************************/
void main()
{
port_init();
init_lcd();
lat_disp (0x00,0x00);
chn_disp (tab1);
delay1ms(5500);
chn_disp (tab2);
spi_init();
start(Command_H,Command_L);
while(1)
{
while(READY); //等待转换结束
getdata();
disp_two_char(0x8a,tab[buffer[4]],tab[buffer[3]]);
disp_two_char(0x8b,tab[buffer[2]],tab[buffer[1]]);
disp_two_char(0x8c,tab[buffer[0]],'V');
start(Command_H,Command_L);
}
}
Previous article:ATmega128 Model Identification Description
Next article:AVR internal EEPROM experiment
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Here is a solution to pedal power and longer battery life
- 【TI recommended course】#MSP432 product training#
- Today at 10:00 AM, Meixin Award-winning Live Broadcast: Integrated Digital IO Technology Supporting Industrial Systems
- 【Gravity:AS7341 Evaluation】+ Detection of specified colors
- [In-depth analysis] Future development trends of the RF market
- Is it difficult to do embedded system? How to learn embedded ARM? Do you need to work 996?
- I saw a hardware open source USB to CAN tool on the Internet
- [GD32E503 Review] 02. Playing with TFT LCD screen and string display
- CircuiteXpert User Series 1: Quick Setup without Plug-in
- 【AT-START-F425 Review】 WS2812 Color Light Ring Display Driver