CSS code to Swordfish

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
madru
Posts: 10
Joined: Thu Oct 22, 2009 9:07 pm

CSS code to Swordfish

Post by madru » Sun Nov 08, 2009 9:05 pm

Hi,

I try now since a couple of hours to translatethe 16F690 CSS C code into Swordfish for 18fxxxx but with no real success on the interrupt routine

the original code looks like this:

Code: Select all

#int_TIMER1
void uberlauf_timer1 (void)           // hier die Timer Überläufe erfassen
{timer1_uberlauf++;}               
/****************************************************************************
 ****************************************************************************/
#int_ext                               // Interrupt service Routine
void interrupt (void)
 {
  if (flanke)                          // wenn gesetzt dann Impuls Ende erkannt 
   { setup_timer_1(T1_DISABLED);       // Timer stop
     dcf77_start_bit=timer1_uberlauf;  // den Überlauf hier abspeichern
     timer1_uberlauf=0;                // lösche für neue Messung
     timer1_H=TMR1H;                   // abspeichern - high Byte Timer
     impuls_ok=1;                      // Merkbit der Impuls liegt an
     restart_wdt();                    // Watchdog zurücksetzen 
     ext_int_edge(L_TO_H);             // Flanke umstellen für (Anfang-Impuls)
     setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); // Timer wieder aktiv           
     flanke=0; }                       // lösche Merkbit neue Messung      
  else 
   { set_timer1(0);                    // lösche Timer * 2µs 
     ext_int_edge(H_TO_L);             // Flanke umstellen für (Ende-Impuls)
     flanke=1; }                       // setze Merkbit zum abspeichern 
 }
  disable_interrupts(GLOBAL);              // Globaler Interrupt sperren 
  disable_interrupts(INT_TIMER1);          // Interrupt für... sperren

  setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);  // Timer einstellen
  timer1_H=0;                              // löschen Inhalt Timer1 high Byte
  timer1_L=0;                              // löschen Inhalt Timer1 low  Byte
  ext_int_edge(L_TO_H);                    // Flanke einstellen
  enable_interrupts(INT_EXT);              // Interrupt für... freigabe
  enable_interrupts(INT_TIMER1);           // Interrupt für... freigabe
  enable_interrupts(GLOBAL);               // Globaler Interrupt Freigabe  

and my translated version like this:

Code: Select all

Interrupt service()
 If (INTCON.4 > 0) And (INTCON.1 > 0) Then
    INTCON.1 = 0
    INTCON2.6 =1  ' INTEDG0 rising edge trigger


   If  flanke = 1 Then                // if 1 Impuls end detected 
     T1CON.0  = 0                     // Timer stop
     dcf77_start_bit=timer1_uberlauf  // store rollover
     timer1_uberlauf=0                // clear for for new measurement
     timer1_H=TMR1H                   // store- high Byte Timer
     impuls_ok=1                      // Impuls detected
     INTCON2.6 =1                     // ext_int_edge(L_TO_H) Startpuls;                   
     TMR1H = $15                      // preset for timer1 MSB register
     TMR1L = $A0                      // preset for timer1 LSB register
     flanke=0                         // clear Merkbit start again     
   Else 
     PIR1.0  = 0                      // clear Timer * 2µs 
     INTCON2.6 =0                     // ext_int_edge(H_TO_L endpulse)
     flanke=1                         // set Merkbit 
   End If                  
 End If  

 If PIR1.0 = 1 Then
    inc(timer1_uberlauf) 
 End If
                
End Interrupt

INTCON.1 = 0  ' INT0IF
INTCON.4 = 1  ' INT0IE
INTCON.6 = 1
INTCON.7 = 1
INTCON2.6 =1  ' INTEDG0 rising edge trigger
INTCON2.7 = 0  ' weak pullups off

//intcon.5 'TMR0IE: TMR0 Overflow Interrupt Enable bit
  TRISB.0 = 1                  ' RB0 is input


T1CON.5 = 1 ' T1CKPS1 bits 5-4  Prescaler Rate Select bits
T1CON.4 = 1        'T1CKPS0
T1CON.3 = 1 ' T1OSCEN bit 3 Timer1 Oscillator Enable Control: bit 1=on
T1CON.2  = 1 ' T1SYNC bit 2 Timer1 External Clock Input Synchronization Control bit: 1=Do not synchronize external clock input
T1CON.1  = 0 ' TMR1CS bit 1 Timer1 Clock Source Select bit: 0=Internal clock (FOSC/4) / 1 = External clock from pin T1CKI (on the rising edge)
T1CON.0  = 1 ' TMR1ON bit 0 enables timer
TMR1H = $15        ' preset for timer1 MSB register
TMR1L = $A0        ' preset for timer1 LSB register
PIR1.0  = 0                  ' clear TMR1IF  

i am not really sure regarding the different timer settings and the 'special' CSS commands, if somebody can give me a hand here?

THX

M

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Nov 09, 2009 7:24 pm

Have a look on the Swordfish Wiki, I did an article which may give you some ideas about the use of interrupts in Swordfish.

http://www.sfcompiler.co.uk/wiki/pmwiki ... 3Interrupt

Also on the Wiki is the Swordfish manual which has an interrupt section.

http://www.sfcompiler.co.uk/downloads/SFManual.pdf

Please have a look at them and come back if there are any more questions!

Good Luck.

Post Reply