Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/20/03 05:26
Read: times


 
#52897 - RE: Trouble with interupts in C
Responding to: ???'s previous message
#include <reg520.h>
#include <stdio.h>
#include <ABSACC.H>

#define on 1
#define off 0

sbit LED0 = P1^7;
sbit LED1 = P1^6;
sbit LED2 = P1^5;
sbit LED7 = P1^0;
sbit SW0 = P2^0;
sbit SW1 = P2^1;
sfr parallel = 0x80;

void sleep( int sleepTimeMax ) { // produce a delay of sleepTimeMax ms
    int sleepTime,msTick = -921;
    TMOD = (TMOD & 0xF0) | 0x01;
    TH0 = msTick / 0x100;
    TL0 = msTick % 0x100;
    TF0 = 0;
    TR0 = 1;
    for ( sleepTime = 0; sleepTime < sleepTimeMax; sleepTime++ ) {
        while ( TF0 == 0 );
        TF0 = 0;
        TH0 = msTick / 0x100;
        TL0 = msTick % 0x100;
    }
}

void serialMemTransfer(void) {
    TI1 = 0;
    XBYTE [0x0000] = SBUF0;
    sleep(10);
    SBUF1 = XBYTE [0x0000];
    sleep(10);
}

void serialInterupt(void) {
    unsigned char x;
    LED2 = on;
    if (RI) {
        if (SW1) {
            sleep(1);
            x = SBUF0;
            sleep(1);
            parallel = x;
            SBUF0 = x;
            sleep(10);
        } else {
            serialMemTransfer();
        }
    }
    LED2 = off;
}

void checkSerialInterupt(void) interrupt 4 {
    serialInterupt();
}

void squareWave(void) interrupt 2 {
    LED1 = on;
    while (!INT1);
    LED1 = off;
}

void ledControl2(void) interrupt 0 {
    LED0 = on;
    while (!INT0);
    LED0 = off;
}

void initSerial( void ) {
//    WDCON |= 0x80;        // Setup double baud
    SCON0 = 0x50;        // SCON: mode 1, 8-bit UART, enable rcvr
    SCON1 = SCON0;
    TMOD |= 0x20;        // TMOD: timer 1, mode 2, 8-bit reload
    TH1   = 0xFD;        // TH1:  reload value for 9600 baud @ 11.0592MHz
    TR1   = on;            // TR1:  timer 1 run
    TI    = on;            // TI:   set TI to send first char of UART
}

void main (void) {
    initSerial();
    IE = 0x95;            // Enable interupts
    LED1 = off;
    LED2 = off;
    LED0 = off;
    while (1) {
        LED7 = SW0;
    }
}


List of 12 messages in thread
TopicAuthorDate
Trouble with interupts in C            01/01/70 00:00      
   RE: Trouble with interupts in C            01/01/70 00:00      
   RE: posting code            01/01/70 00:00      
   RE: Trouble with interupts in C            01/01/70 00:00      
      RE: Trouble with interupts in C            01/01/70 00:00      
         RE: Trouble with interupts in C            01/01/70 00:00      
            RE: Trouble with interupts in C            01/01/70 00:00      
               RE: Trouble with interupts in C            01/01/70 00:00      
   RE: Trouble with interupts in C            01/01/70 00:00      
      RE: Trouble with interupts in C            01/01/70 00:00      
      RE: Trouble with interupts in C            01/01/70 00:00      
   RE: Trouble with interupts in C            01/01/70 00:00      

Back to Subject List