Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum

Re: conversie word to hex Kategorie: IDE (von Tobias - 5.02.2017 23:23)
Als Antwort auf Re: conversie word to hex von Bram Vooys - 5.02.2017 21:45

Dear Bram,

please try this. I hope it's what you needed. Otherwise I didn't understood you correctly.
I only included the transformation from decimal value in a hex-formatted string and send it
over the serial interface.
I didn't checked any other things at your code!

Regards, Tobias


/*******************************************************************************
name:           - Inertia Dyno Power. Timer Moduul basis Timer0.
input:          - Wheel sensor
output:         - Timer Counts Seriel (prefer dec or hex) to the PC for Delphi interface
description:    - Timer0 Interrupt, if timer has expired

Mega32:  Output PD7 (PortD.7) for Test
*******************************************************************************/



#ifdef MEGA32
#define PORT_PWM 31
#endif

#define EXTINT 2
#define INTMODE 2

#define LF 0x0A
#define CR 0x0D
#define SPACE 0x20

word cnt1;
byte busy;
char str[6];
/*------------------------------------------------------------------------------
name:           - Inertia Dyno Power. Timer Moduul
input:          - Sensor
output:         - Timer Counts Seriel (dec or hex) to PC for Grafics (Delphi)
description:    - Timer0 Interrupt, if timer has expired
------------------------------------------------------------------------------*/


void Ext_ISR(void)
{
int irqcnt;

   Timer_T0Stop();                 // Timer 0 Stop
//    cnt1  = value timer pulses in word ?
// ?  Str_Printf(str, "arg1: %dr", 1234);
// ?  Str_Printf '=(%[width]x -> Hex-number)
//    and send it then with
// ?  Serial_WriteText(0,str);
// ?  Serial_Write(0,cnt1);

////////////////////////////////////////////////////////////////////////////////
    Str_Printf(str, "%04xr", cnt1);  //Transform word to 4 digit hex (e.g. 65535 to FFFF)
                                      //The "r" is a CR directly in the string
    Serial_WriteText(0,str);          //Send the string to the serial interface
////////////////////////////////////////////////////////////////////////////////
//    Serial_Write(0,CR);            //It's in the string includes, see above!  // Send CR to PC forr Deplhi grafics interface
    cnt1=0;                          // Set counter value 0
    Ext_IntDisable(EXTINT);          // Disable Ext Interupt
    Timer_T0FRQ(4,PS0_1024);         // Start Timer again
    Ext_IntEnable(EXTINT,INTMODE);   // Ext Interupt enable
    irqcnt=Irq_GetCount(INT_2);      // activeer interupt INT_2 from wheel speed
}

void Timer0_ISR(void)
{
int irqcnt;
busy=0;
irqcnt=Irq_GetCount(INT_TIM0COMP);      // Interrupt Request Counter
}

void main(void)
{
    Serial_Init(0,SR_8BIT|SR_1STOP|SR_NO_PAR,SR_BD9600);
    Port_DataDirBit(PORT_PWM,PORT_OUT);     // Set port direction to output
    Irq_SetVect(INT_TIM0COMP,Timer0_ISR);   // Define Interrupt
    Irq_SetVect(INT_2,Ext_ISR);             // From (wheel) sensor to pin nr.10

    while (1)
    {
        Timer_T0Time(4,PS0_1024);         // Ca. 1 ms need more adjusting
        Port_WriteBit(PORT_PWM,0);        // Set port to control output to 0
        busy=1;
        while (busy);
        Timer_T0Time(4,PS0_1024);         //
        Port_WriteBit(PORT_PWM,1);        // Set port to control output to 1
        busy=1;
        while (busy);
        cnt1++;                           // Added Timer Pulses
        Ext_IntEnable(EXTINT,INTMODE);    // Enable Ext. Interupt
    }
  }

// EOF


    Antwort schreiben


Antworten:

Re: conversie word to hex (von Tobias - 5.02.2017 23:35)