Code :
- /****************************************************************/
- /* This C file is the translation of the DSP codes provided in: */
- /* - adcmain.dsp */
- /* - adcsamp.dsp */
- /* - ioutils.dsp */
- /* The aim of this file is to show how to translate a assembly */
- /* code in C. */
- /* Author : Krz Aramis Date : 13.06.2002 */
- /* File : ADC.c Last Modified : 18.06.2002 */
- /* Purpose : */
- /* The Max153 is tested by reading a 0-5V input on Vin */
- /* into PortA and displaying the digitised value on port B.*/
- /* The Max153 is interface to the PPI lines as follows: */
- /* PC7 --->> /INT PC1 --->> /CS PC0 --->> //RD */
- /* Port A --->> ADC data lines Port B --->> Led display */
- /****************************************************************/
- #include "portADC.h" // Custom header file
- // Some declaration missing
- #define write(port, data) = _asm("IO(ar) = ax0;" );
- #define read(data, port) = _asm("ar = IO(ax0);" );
- .const IntMask = 0x80;
- // global varaible declaration missing
- void main()
- {
- Dm_Wait_Reg = 0x08; // Check if possible
- write(PPIctrl, 0x98); // Check if possible
- do
- {
- SetHigh( 0x02 , PortC ); // Call state1 with CSHigh and PortC
- SetHigh( 0x01 , PortC ); // Call state1 with RDhigh and PortC
- Ready( IntMask , PortC );
- SetLow( 0xfd , PortC );
- SetLow( 0xfe , PortC );
- Valid( IntMask , PortC );
- read(data, PortA); // call macro "read from port"
- _asm("nop;\
- nop;\
- nop;\
- nop;" );
- write(PortB, data); // call macro "write to port"
- }
- while(1);
- }
- /****************************************************************/
- /* The following sub program replaces this assembly code: */
- /* First time it executed: */
- /* ax0 = CSHi; { Set CS high } */
- /* ay0 = IO(PortC); */
- /* ar = ax0 or ay0; */
- /* IO(PortC) = ar; */
- /* At the Second Time it is executed: */
- /* ax0 = RDhi; { Set RD high } */
- /* ay0 = IO(PortC); */
- /* ar = ax0 or ay0; */
- /* IO(PortC) = ar; */
- /****************************************************************/
- SetHigh(int x, int y)
- {
- _asm("ay0 = ar or ax0;" ); // Can be re-write in C
- _asm("IO(PortC) = ay0;" ); // Macro Creation Requiered
- }
- /****************************************************************/
- /* wait until ADC ready */
- /****************************************************************/
- Ready(int x, int y)
- {
- do
- {
- _asm("ay0 = ar and ax0;" );
- }
- while(ar == ax0);
- }
- /****************************************************************/
- /* The following sub program replaces this assembly code: */
- /* First time it executed: */
- /* ax0 = CSlo; { Set CS low } */
- /* ay0 = IO(PortC); */
- /* ar = ax0 and ay0; */
- /* IO(PortC) = ar; */
- /* At the Second Time it is executed: */
- /* ax0 = RDlo; { Set RD low } */
- /* ay0 = IO(PortC); */
- /* ar = ax0 and ay0; */
- /* IO(PortC) = ar; */
- /****************************************************************/
- SetLow(int x, int y)
- {
- _asm("ay0 = ar and ax0;" ); // Can be re-write in C
- _asm("IO(PortC) = ay0;" ); // Macro Creation Requiered
- }
- /****************************************************************/
- /* wait valid data */
- /****************************************************************/
- Valid(int x, int y);
- {
- do
- {
- _asm("ay0 = ar and ax0;" );
- }
- while(ar != ax0);
- }
|