📄 gene_val.c
字号:
//*----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : gene_val.c
//* Object : Analog value generation for the AT91EB55
//*
//* 1.0 00/00/00 JCZ : Creation
//*----------------------------------------------------------------------------
#ifndef AT91_DEBUG_NONE
#include <stdio.h>
#endif
#include "parts/m55800/lib_m55800.h"
#include "targets/eb55/eb55.h"
#include "drivers/analog/analog.h"
#include "lib_tools.h"
extern AnalogDescDac AnalogDac;
// * Local variable
static const char main_menu[]=
{
"\n\r COMMAND MENU: gene Value\n\r"
" 0) Info \n\r"
" 1) Set DC Value \n\r"
" 2) Set Resolution \n\r"
" 4) Update DAC 0\n\r"
" 5) Update DAC 1\n\r"
" 6) Stop DAC 0\n\r"
" 7) Stop DAC 1\n\r"
" 8) Run and init DAC 0 \n\r"
" 9) Run and init DAC 1 \n\r"
" 99) Quit program\n\r"
"Enter command to execute: "
};
//*----------------------------------------------------------------------------
//* Function Name : Get_Command_val
//* Object : Get command val
//* Input Parameters : None
//* Output Parameters : int : Command num
//*----------------------------------------------------------------------------
int Get_Command_val(void)
{
int command;
at91_print_frame(&COM,(char *)main_menu,sizeof(main_menu));
at91_scanf(&COM,"%d", &command);
at91_print_crlf(&COM);
return command;
}
//*----------------------------------------------------------------------------
//* Function Name : menu
//* Object : check general menu
//* Input Parameters : None
//* Output Parameters : None
//*----------------------------------------------------------------------------
void menu_val(void)
{
int command = 0;
int Value = 0;
int dac_res =0;
int dac_mode=0;
while(command!=99)
{
command = Get_Command_val();
switch(command)
{
case 0: /* Info */
if ( (dac_mode & DAC_8_BIT_RES)== DAC_8_BIT_RES )
{
at91_print(&COM,"DAC in 8 bits mode");
}
else
{
at91_print(&COM,"DAC in 10 bits mode");
}
sprintf(message,":%04X \n\r",dac_mode);
at91_print(&COM,message);
sprintf(message,"DC Value: %d Hex:%04X \n\r",Value,Value);
at91_print(&COM,message);
break;
case 1: /* Set DC Value */
at91_print(&COM,"DC Value (Hex):");
at91_scanf(&COM,"%X", &Value);
sprintf(message,"\n\r%d Hex:%04X \n\r",Value,Value);
at91_print(&COM,message);
break;
case 2: /* Get Resolution */
at91_print(&COM,"Resolution 0 for 10 bits or 1 for 8 bits:");
at91_scanf(&COM,"%X", &dac_res);
if ( dac_res == 1 )
dac_mode |= DAC_8_BIT_RES;
else
dac_mode &= ~DAC_8_BIT_RES;
break;
case 4: /* */
AnalogDac.dac=&DAC0_DESC;
at91_analog_write_dac(&AnalogDac, (u_short *)&Value );
break;
case 5: /* */
AnalogDac.dac=&DAC0_DESC;
at91_analog_write_dac(&AnalogDac, (u_short *)&Value );
break;
case 6: /* Command Reset */
AnalogDac.dac=&DAC0_DESC;
AnalogDac.timer=0;
at91_analog_close_dac( &AnalogDac);
break;
case 7: /* Command Reset */
AnalogDac.dac=&DAC1_DESC;
AnalogDac.timer=0;
at91_analog_close_dac(&AnalogDac);
break;
case 8: /* */
AnalogDac.dac=&DAC0_DESC;
AnalogDac.timer=0;
at91_analog_open_dac(&AnalogDac,dac_mode);
at91_analog_write_dac(&AnalogDac, (u_short *)&Value );
break;
case 9: /* */
AnalogDac.dac=&DAC1_DESC;
AnalogDac.timer=0;
at91_analog_open_dac(&AnalogDac,dac_mode);
at91_analog_write_dac(&AnalogDac, (u_short *)&Value );
case 99: /* quit */
break;
default: /* invalid command */
at91_print(&COM,"Invalid command entered. Please enter again!\n\r");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -