ABOV program - small item 01 - mobile monitoring motion platform control

Article catalog Prompt: ABOV realizes multi c...
1. Application scenario setting
2. Methods used
3. Setting of final realization
1. Complete the three-dimensional modeling of the experimental structure
2. Complete the concept of communication mode
3. Complete slave debugging
3. Complete host commissioning
1. Renderings
2. Schematic diagram
3. Procedure
Article catalog

Prompt: ABOV realizes multi computer communication control to realize the control of mobile monitoring motion platform

preface

Tip: Here you can add the general contents to be recorded in this article:
For example, with the continuous development of artificial intelligence, machine learning technology is becoming more and more important. Many people have started learning machine learning. This paper introduces the basic content of machine learning.

Tip: the following is the main content of this article. The following cases can be used for reference

1, What is ABOV?



ABOV semiconductor was separated from HYNIX in Korea in 2006 and has more than 20 years of experience in the field of single chip microcomputer. ABOV semiconductor has alternative products of single chip microcomputer and standard IC

2, Application settings

1. Application scenario setting

The product is used to automatically test the sensing effect of human body sensing PIR at different distance angles

2. Methods used

1. Inventor 3D modeling 2.ABOV single chip microcomputer as mechanical control IC

IO output AD detection serial port communication

3.STM32 single chip microcomputer is used as the system terminal control IC 4.C # as computer terminal control software

3. Setting of final realization

Realize the control of two motion mechanisms, complete the test of products to be tested on the mechanism, and return the data to the multi-channel terminal

2, Use steps

1. Complete the three-dimensional modeling of the experimental structure

The host build model is as follows:


The modeling of the mechanism is as follows:

After the installation of the two structures, the following are:

2. Complete the concept of communication mode

The code is as follows (example):

3. Complete slave debugging

The slave commissioning is as follows:

3. Complete host commissioning

3, Slave production

1. Renderings

ABOV mobile trolley slave

ABOV slave movement effect

2. Schematic diagram


3. Procedure

Download source code ---- >

Code generator configuration:
Keil completed the following code:

OCD2 completes the simulation:

1. Main program

main.c:

//====================================================== // Main program routine // - Device name : MC95FG308 // - Package type : 28SOP //====================================================== // For XDATA variable : V1.041.00 ~ #define MAIN 1 // Generated : Fri, Nov 12, 2021 (21:10:31) #include "MC95FG308.h" #include "func_def.h" #include "IO_code.h" #include "usart_code.h" #include "function_code.h" void main() { cli(); // disable INT. during peripheral setting port_init(); // initialize ports clock_init(); // initialize operation clock ADC_init(); // initialize A/D convertor Timer0_init(); // initialize Timer0 UART_init(); // initialize UART interface sei(); // enable INT. // TODO: add your main code here placeX_now = 0; //Power on, the default is 0 coordinate while(1){ fn_function_check(); //Processing function here // TODO: add other code here } } //====================================================== // interrupt routines //====================================================== void INT_USART0_Rx() interrupt 6 { // USART0 Rx interrupt // TODO: add your code here dataR0 = UART_read(0); fn_check_usart(0,&dataR0); //UART_write(0,dataR0); } void INT_USART1_Rx() interrupt 10 { // USART1 Rx interrupt // TODO: add your code here } void INT_Timer0() interrupt 12 { // Timer0 interrupt // TODO: add your code here Led_Time_Change(100); } void INT_ADC() interrupt 18 { // ADC interrupt // TODO: add your code here } void INT_BIT() interrupt 22 { // BIT interrupt // TODO: add your code here } //====================================================== // peripheral setting routines //====================================================== unsigned char UART_read(unsigned char ch) { unsigned char dat; if (ch == (unsigned char)0) { // UART0 while(!(USTAT & 0x20)); // wait dat = UDATA; // read } if (ch == (unsigned char)1) { // UART1 while(!(USTAT1 & 0x20)); // wait dat = UDATA1; // read } return dat; } unsigned int ADC_read() { // read A/D convertor unsigned int adcVal; while(!(ADCM & 0x10)); // wait ADC busy adcVal = (ADCRH << 8) | ADCRL; // read ADC ADCM &= ~0x40; // stop ADC return adcVal; } void ADC_init() { // initialize A/D convertor ADCM = 0x00; // setting ADCM2 = 0x04; // trigger source, alignment, frequency IEN3 |= 0x01; // enable ADC interrupt } void ADC_start(unsigned char ch) { // start A/D convertor ADCM = (ADCM & 0xf0) | (ch & 0xf); // select channel ADCM |= 0x40; // start ADC } void Timer0_init() { // initialize Timer0 // 8bit timer, period = 9.984000mS T0CR = 0x96; // timer setting T0DR = 0xE9; // period count IEN2 |= 0x01; // Enable Timer0 interrupt T0CR |= 0x01; // clear counter } void UART_init() { // initialize UART interface // UART0 : ASync. 9615bps N 8 1 UCTRL2 = 0x02; // activate UART0 UCTRL1 = 0x06; // Async/Sync, bit count, parity UCTRL2 |= 0xAC; // interrupt, speed //UCTRL2 |= 0x10; // enable line when you want to use wake up in STOP mode UCTRL3 = 0x00; // stop bit UBAUD = 0x4D; // baud rate // UART1 : ASync. 9615bps N 8 1 UCTRL12 = 0x02; // activate UART1 UCTRL11 = 0x06; // Async/Sync, bit count, parity UCTRL12 |= 0xAC; // interrupt, speed //UCTRL12 |= 0x10; // enable line when you want to use wake up in STOP mode UCTRL13 = 0x00; // stop bit UBAUD1 = 0x4D; // baud rate IEN1 |= 0x11; // enable UART interrupt } void UART_write(unsigned char ch, unsigned char dat) { if (ch == (unsigned char)0) { // UART0 while(!(USTAT & 0x80)); // wait UDATA = dat; // write } if (ch == (unsigned char)1) { // UART1 while(!(USTAT1 & 0x80)); // wait UDATA1 = dat; // write } } void clock_init() { // external clock cli(); IEN3 |= 0x10; // Enable BIT interrupt sei(); BCCR = 0x05; // 16msec BIT SCCR = 0x81; // External clock PCON = 0x03; // STOP1 mode entry _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); SCCR &= ~0x80; // clock changed IEN3 &= ~0x10; // Disable BIT interrupt } void port_init() { // initialize ports // 3 : AN4 in // 8 : P10 out // 9 : P11 out // 16 : TxD1 out // 17 : RxD1 in // 19 : XIN in // 20 : XOUT out // 25 : TxD0 out // 26 : RxD0 in // 28 : P31 out P0IO = 0xE7; // direction P0PU = 0x08; // pullup P0OD = 0x00; // open drain P0DB = 0x00; // debounce P0 = 0x00; // port initial value P1IO = 0xFB; // direction P1PU = 0x00; // pullup P1OD = 0x00; // open drain P1DB = 0x00; // debounce P1 = 0x00; // port initial value P2IO = 0xFE; // direction P2PU = 0x00; // pullup P2OD = 0x00; // open drain P2DB = 0x00; // debounce P2 = 0x00; // port initial value P3IO = 0x7F; // direction P3PU = 0x80; // pullup P3OD = 0x00; // open drain P3DB = 0x00; // debounce P3 = 0x00; // port initial value // Set port function PSR0 = 0x10; // AN7 ~ AN0 PSR1 = 0x00; // I2C, AN14 ~ AN8 }

1.IO program

IO_code.h :

#ifndef _IO_CODE_ #define _IO_CODE_ #include "MC95FG308.h" #include "func_def.h" #define TIME_Goforward six // Time is the forward control time #define TIME_GoBACK_Long 18 // Time is the fallback long control time #define TIME_GoBACK_short 6 // The time is the fallback short control time #define IO_ Goforward P11 / / IO port is the forward control port #define IO_GoBACK P10 / / IO port is the reverse control port unsigned int fn_IO_run(unsigned char distance); //Forward control procedure unsigned int fn_IO_goback(unsigned char back_time); //Reverse control procedure void delay_ms(unsigned int count); void delay_us(unsigned int count); void delay_s(unsigned int count); void Led_Time_Change(unsigned int count); void Led_flash(void); #endif

IO_code.c :

#include "IO_code.h" #include "usart_code.h" #include "function_code.h" /************************************************************ * @brief * unsigned int fn_IO_run(unsigned char distance) * @param * @retval *************************************************************/ unsigned int fn_IO_run(unsigned char distance){ // Forward control procedure unsigned char xdistance; if(distance<=placeX_MIN) // Advance cannot be less than the minimum displacement coordinate for(xdistance=0 ;xdistance<distance ;xdistance++ ){ IO_Goforward = 1 ; delay_s(1); IO_Goforward = 0 ; //Cycle forward delay_s(TIME_Goforward); if(bdata_effect==1){ //Zhongtong received the new instruction and went out return xdistance; } } return xdistance; } /************************************************************ * @brief * unsigned int fn_IO_goback(unsigned char back_time) * @param * @retval *************************************************************/ unsigned int fn_IO_goback(unsigned char back_time){ // Reverse control procedure IO_GoBACK = 1 ; delay_s(1); IO_GoBACK = 0 ; delay_s(back_time); if(bdata_effect==1){ return 2; } return 0; } /************************************************************ * @brief * void Led_Time_Change(unsigned int count) * @param * @retval *************************************************************/ unsigned char count_Ledtime; void Led_Time_Change(unsigned int count){ //IO flashes in interrupt timer if(count_Ledtime++>count){ count_Ledtime=0; P31 = ~P31; } } /************************************************************ * @brief * void Led_flash(void) * @param * @retval *************************************************************/ void Led_flash(void){ P31 = ~P31; delay_ms(100); P31 = ~P31; delay_ms(100); P31 = ~P31; } /************************************************************ * @brief * Delay function * @param * @retval *************************************************************/ void delay_us(unsigned int count){ unsigned int a=0 ; for(a=0;a<count;a++){ ; } } //----------------------------------------------------- void delay_ms(unsigned int count){ unsigned int a=0,b=0; for(a=0;a<count;a++){ delay_us(400); } } void delay_s(unsigned int count){ unsigned int a=0,b=0; for(a=0;a<count;a++){ delay_ms(1100); if(bdata_effect==1){ return; } } }

2.USAR serial port program

usart_code.c:

#ifndef _USART_CODE_ #define _USART_CODE_ #include "MC95FG308.h" #include "func_def.h" extern volatile unsigned char bdata_begin ; extern volatile unsigned char bdata_judge ; extern volatile unsigned char bdata_effect ; extern volatile unsigned char bdata_error ; #define _DATA_GET 0xAB #define _DATA_GET_CODE 4 #define _DATA_GET_MODE 7 #define U_Scom_car 0xBA #define U_Scom_code1 0x01 // start #define U_Scom_code2 0x02 // suspend #define U_Scom_code3 0x03 // Displacement to target coordinate attachment #define U_Scom_code4 0x04 // Start test target coordinates #define U_Scom_code5 0x05 // Return to starting point #define U_Scom_code6 0x06 // reset #define U_Scom_code7 0x07 // fault extern unsigned char UART_SENDCODE[_DATA_GET_CODE]; extern unsigned char dataR0 ; extern unsigned char UART_GETcommand_car; //Final device address of serial port extern unsigned char UART_GETcommand_code; //Serial port final command extern unsigned char UART_GETcommand_X; //Final X command of serial port extern unsigned char UART_GETcommand_Y; //Final Y command of serial port void fn_usart_senddata(unsigned char ch, unsigned char *dat ,unsigned int num ); void fn_check_usart(unsigned char ch,unsigned char *dataget); void fn_usart_sendcommande(unsigned char com_car, unsigned char com_code ,unsigned char com_X , unsigned char com_Y ); #endif

usart_code.c :

#include "usart_code.h" #include "IO_code.h" volatile unsigned char bdata_begin ; volatile unsigned char bdata_judge ; volatile unsigned char bdata_effect ; //----------------------Receive corresponding code value--------------------------------- const unsigned char UART_GETCODE[_DATA_GET_MODE][_DATA_GET_CODE]= {,//start ,//suspend ,//Displacement to target coordinate attachment ,//Start test target coordinates ,//Return to starting point ,//reset };//fault volatile unsigned char uart_get_buffer[4]=; //Serial port receiver byte buffer //----------------------Send corresponding code value memory--------------------------------- volatile unsigned char UART_SENDCODE [_DATA_GET_CODE]=; volatile unsigned char dataR0 = 0; //Serial port single byte buffer volatile unsigned char UART_GETcommand_car; //Final device address of serial port volatile unsigned char UART_GETcommand_code; //Serial port final command volatile unsigned char UART_GETcommand_X; //Final X command of serial port volatile unsigned char UART_GETcommand_Y; //Final Y command of serial port /************************************************************ * @brief * void fn_usart_senddata( // Serial port multi data sending function encapsulates the sending program of single sub section function unsigned char ch, //Serial port number unsigned char *dat, //Serial port sending data address unsigned int num ) //Number of data sent by serial port * @param * @retval *************************************************************/ void fn_usart_senddata(unsigned char ch, unsigned char *dat ,unsigned int num ){ unsigned int i; for(i=0 ; i<num ; i++){ UART_write(ch,dat[i]); //Multibyte write operation } } /************************************************************ * @brief * static void fn_get_usart( unsigned char ch, //Serial port number unsigned char *dataget) //Serial port single byte received data variable address * @param * @retval *************************************************************/ static void fn_get_usart(unsigned char ch,unsigned char *dataget){ //Serial port receiving customized function static unsigned char num_dataget; //Static record number variable unsigned char data_dataget; data_dataget = *dataget ; if(ch == 0){ //USAR 0 serial port if(bdata_begin == 0){ uart_get_buffer[0]=0x00; // Clean up instruction cache set variable space uart_get_buffer[1]=0x00; uart_get_buffer[2]=0x00; uart_get_buffer[3]=0x00; if(data_dataget ==_DATA_GET){ //Judge whether the instruction start corresponds to the start variable bdata_begin =1; bdata_judge = 0; num_dataget = 0; //When a specific instruction is recognized, data is recorded }else{ num_dataget = 0; //Whether it is the beginning keyword in the instruction is recognized_ DATA_GET bdata_judge = 0; return; } } uart_get_buffer[num_dataget++]=data_dataget; //Data storage of instruction buffer if(num_dataget==_DATA_GET_CODE){ //Record the signal of specified length bdata_begin =0; num_dataget = 0; bdata_judge = 1; // Signal successfully intercepted flag bit } } } /************************************************************ * @brief * static void fn_effect_usart( unsigned char ch, //Serial port number unsigned char *dataget) //Serial port single byte received data variable address * @param * @retval *************************************************************/ static void fn_effect_usart(unsigned char ch,unsigned char *dataget){ unsigned char ndec=0; // 2D row coordinates unsigned char ndem=0; // 2D ordinate unsigned char effect_data=0; // Instruction judgment buffer unsigned char effect_data2=0; // Instruction judgment buffer if(ch==0){ if(bdata_judge==0) // Signal successfully intercepted flag bit bdata_judge = 0; for(ndem=0 ;ndem<_DATA_GET_MODE ;ndem++ ){ //Traversal instruction set pair for(ndec = 0;ndec<_DATA_GET_CODE-2 ;ndec++){ //Subtract 2 because the X Y instruction does not make a judgment effect_data = dataget[ndec]; effect_data2 = UART_GETCODE[ndem][ndec]; if(UART_GETCODE[ndem][ndec] != dataget[ndec] ){ // If you traverse to the corresponding instruction position break; } if(ndec==_DATA_GET_CODE-1-2){ //If it is judged that two instructions in the length of 4 instructions correspond to each other, that is, UART_GETcommand_car UART_ GETcommand_ You can store instructions on the corresponding code UART_GETcommand_car = dataget[0]; //Final device address of serial port UART_GETcommand_code = dataget[1]; //Serial port final command UART_GETcommand_X = dataget[2]; //Final X command of serial port UART_GETcommand_Y = dataget[3]; //Final Y of serial port fn_usart_senddata(0,dataget,_DATA_GET_CODE); //Return the intercepted correct instruction to the host dataget[0]=0x00; // Clear buffer after storage dataget[1]=0x00; dataget[2]=0x00; dataget[3]=0x00; bdata_effect = 1; // The directive came into force return; } } } dataget[0]=0x00; //It has been convenient for a long time. I haven't found the corresponding instruction dataget[1]=0x00; dataget[2]=0x00; dataget[3]=0x00; } } /************************************************************ * @brief * void fn_check_usart( unsigned char ch, //Serial port number unsigned char *dataget) //Serial port single byte received data variable address * @param * @retval *************************************************************/ void fn_check_usart(unsigned char ch,unsigned char *dataget){ //The external judgment interface function encapsulates the above programs if(bdata_effect==1) fn_get_usart(ch , dataget); fn_effect_usart(ch , uart_get_buffer); } /************************************************************ * @brief * void fn_usart_sendcommande( unsigned char com_car, unsigned char com_code, unsigned char com_X, unsigned char com_Y ) * @param Instruction sending function * @retval *************************************************************/ void fn_usart_sendcommande(unsigned char com_car, unsigned char com_code ,unsigned char com_X , unsigned char com_Y ){ UART_SENDCODE[0] = com_car; UART_SENDCODE[1] = com_code; UART_SENDCODE[2] = com_X; UART_SENDCODE[3] = com_Y; fn_usart_senddata(0,UART_SENDCODE,_DATA_GET_CODE); }

3. function

function_code.h:

#ifndef _FUNCTION_CODE_ #define _FUNCTION_CODE_ #include "MC95FG308.h" #include "func_def.h" #include "IO_code.h" #include "usart_code.h" #define placeX_MAX 6 // The longest distance of equipment operation unit: M #define placeX_MIN 0 // The maximum running distance of the equipment is in meters extern volatile unsigned int placeX_now ; // Record the current position in meters extern volatile unsigned int placeX_aim ; // Record the data position sent from the serial port, unit: M void fn_function_check(void); //Behavior action function #endif

function_code.c:

#include "function_code.h" #include "usart_code.h" #include "IO_code.h" volatile unsigned int placeX_now = 0; volatile unsigned int placeX_aim = 0; void fn_function_check(void){ if(bdata_effect==0) // The serial port recognizes a valid data flag bit bdata_effect = 0; // Clear the valid data flag bit recognized by the serial port to start execution IO_Goforward = 0; // Close the forward IO port IO_GoBACK = 0; // Close the backward IO port switch(UART_GETcommand_code){ //Recognized instructions case 0x01: //start placeX_now = 0; //Initially set the current position as x=0 fn_usart_sendcommande(U_Scom_car, U_Scom_code1,placeX_now,0x00); //Send the vehicle number, send the command and return the current coordinates to the host break; case 0x02: //suspend fn_usart_sendcommande(U_Scom_car, U_Scom_code2,placeX_now,0x00);//Send the vehicle number, send the command and return the current coordinates to the host break; case 0x03: //Displacement to target coordinate attachment if((UART_GETcommand_X<placeX_now)||(UART_GETcommand_X<placeX_MIN)||(UART_GETcommand_X>placeX_MAX)){ fn_usart_sendcommande(U_Scom_car, U_Scom_code3,0xFF,0xFF);break; //Send abnormal signal 0xFF } // The moving target coordinate cannot be less than the current coordinate, lower than the minimum coordinate or higher than the maximum coordinate placeX_aim = UART_GETcommand_X; //Get target coordinates placeX_now += fn_IO_run(placeX_aim-placeX_now); // The device starts running and updates the current coordinates fn_usart_sendcommande(U_Scom_car, U_Scom_code3,placeX_now,0x00); //Send the vehicle number, send the command and return the current coordinates to the host break; case 0x04: //Start test target coordinates if((UART_GETcommand_X<placeX_now)||(UART_GETcommand_X>placeX_MAX)||(UART_GETcommand_X<placeX_MIN+1)){ fn_usart_sendcommande(U_Scom_car, U_Scom_code4,0xFF,0xFF);break; //Send abnormal signal 0xFF } // The moving target coordinate cannot be less than the current coordinate, lower than the minimum coordinate or higher than the maximum coordinate placeX_aim = UART_GETcommand_X; //Get target coordinates //----------------------------Focus on the last step of the test------------------------- placeX_now += fn_IO_run(placeX_aim-placeX_now-1); //Quickly move to the previous coordinate of the point to be tested delay_s(2); //Wait 2 seconds to enter the target step test placeX_now += fn_IO_run(placeX_aim-placeX_now); // Enter the next step of the target test fn_usart_sendcommande(U_Scom_car, U_Scom_code4,placeX_now,0x00); //Send the vehicle number, send the command and return the current coordinates to the host break; case 0x05: //Return to starting point placeX_aim=0; placeX_now = fn_IO_goback(TIME_GoBACK_Long); //Execute return reset behavior fn_usart_sendcommande(U_Scom_car, U_Scom_code5,placeX_now,0x00); //Send the vehicle number, send the command and return the current coordinates to the host break; case 0x06: //reset Led_flash(); placeX_aim=0; if(placeX_now==0){ fn_IO_run(0x01); //Take a step forward or step back to the wall placeX_now = fn_IO_goback(TIME_GoBACK_short); //Execute return reset behavior }else{ placeX_now = fn_IO_goback(TIME_GoBACK_Long); //Execute return reset behavior } fn_usart_sendcommande(U_Scom_car, U_Scom_code6,placeX_now,0x00); //Send the vehicle number, send the command and return the current coordinates to the host break; case 0x07: //fault bdata_effect = 0; fn_usart_sendcommande(U_Scom_car, U_Scom_code7,placeX_now,0x00); //Send the vehicle number, send the command and return the current coordinates to the host break; } }
summary

To be continued.

16 November 2021, 23:28 | Views: 4536

Add new comment

For adding a comment, please log in
or create account

0 comments