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 Bram Vooys - 5.02.2017 21:45)
Als Antwort auf Re: conversie word to hex von Tobias - 5.02.2017 18:39
Ich nutze:
C-Control Pro Mega32, CC-Pro 32 Application Board
Dear Tobias,

Thank for your replay.I like it.
Below the code.
Please check the comment for futhereplanations.

Regards Bram


/*******************************************************************************
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;
/*------------------------------------------------------------------------------
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);
    Serial_Write(0,CR);              // 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
























>
> Please note, that the Serial_Write-function only can send a byte, not a word!


    Antwort schreiben


Antworten:

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