Example #1
0
void intrrupt_RCIF(void) {
    uint8_t i;
    uint8_t ascii = RCREG1;
    tx_send(ascii);
    if (ascii == '\b') {// back space
        if (scroll_char_pointer > 0) {
            scroll_char_pointer--;
        }
    } else if (ascii == 0x7F) {// delete
        scroll_char_pointer = 0;
        scroll(0);
    } else if (ascii == '\r') {// carriage return
        if (scroll_char_pointer) {
            tx_send('\n');
            return_reset = 1;
        }
        scroll_pointer = 0;
        scroll(1);
    } else if ((ascii >= 0x20)&(ascii <= 0x7E)) {// character
        if (return_reset == 1) {
            return_reset = 0;
            scroll_char_pointer = 0;
        }
        scroll_char[scroll_char_pointer] = ascii;
        scroll_char_pointer++;
        scroll(1);
    }
}
int main(void) {
    OSC_init();
    TRISA = 0b00000000;
    TRISB = 0b00000011;
    TRISC = 0b10000000;
    ANCON0 = 0b11111111;
    ANCON1 = 0b00011111;
    INTCON2bits.RBPU = 0; // Pull-up enable

    timer0_init(3);

    UART_init();
    uint8_t txbuf[100];
    ringbuf_init(&tx_buf, txbuf, sizeof (txbuf));

    INTCONbits.GIE = 1;

    while (1) {
        static int16_t prev_e;
        if (encoder != prev_e) {
            prev_e = encoder;
            if (encoder < 0) {
                tx_send('-');
                tx_sendn(-encoder, 5);
                tx_send('\n');
            } else {
                tx_sendn(encoder, 5);
                tx_send('\n');
            }
        }
    }
    return 0;
}
Example #3
0
/**
 * Apply a ward to a transaction as it is being initialized.
 */
int txward_init(tx_t *tx)
{
  tx_context_t ctx;
  tx_ward_t ward;
  int err;

  memset(&ctx, 0, sizeof(ctx));
  err = inittx_context(&ctx, tx, NULL);
  if (err)
    return (err);

  err = tx_save(&ctx);
  if (err)
    return (err);

  memset(&ward, 0, sizeof(ward));
  err = inittx_ward(&ward, tx, &ctx);
  if (err)
    return (err);

  err = tx_send(NULL, (tx_t *)&ward);
  if (err)
    return (err);

  err = tx_save(&ward);
  if (err)
    return (err);

  tx->tx_flag |= TXF_WARD;

  return (0);
}
void interrupt isr(void) {
    interrupt_TXIF();
    if (RCIF) {
        RCIF = 0;
        tx_send(RCREG);
    }
    if (TMR1IF == 1) {
        TMR1IF = 0;
        cnt_t1++;
        if (cnt_t1 % 16 == 0)LATB0 = ~LATB0;
        button_timer_interrupt(&sw_RA0, !RA0);
        button_timer_interrupt(&sw_RA1, !RA1);
    }
}
Example #5
0
static void ping_test(void)
{
  struct timeval start, end;
  int i, usec;

  rx_post_8();

  gettimeofday(&start, NULL);
  for( i = 0; i < cfg_iter; ++i ) {
    tx_send();
    if( i % 8 == 0 )
      rx_post_8();
    rx_wait();
  }
  gettimeofday(&end, NULL);

  usec = (end.tv_sec - start.tv_sec) * 1000000;
  usec += end.tv_usec - start.tv_usec;
  printf("round-trip time: %0.3f usec\n", (double) usec / cfg_iter);
}
Example #6
0
int main(void) {
    //pin設定
    ANSELA = 0x00;
    ANSELB = 0x00;
    ANSELC = 0x00;
    TRISA = 0x00;
    TRISB = 0xFF;
    TRISC = 0x90;

    OSCCONbits.IRCF = 6; // 6 => 8MHz
    OSCCON2bits.PLLRDY = 1;
    OSCTUNEbits.PLLEN = 1; // clock x 4

    T0CONbits.TMR0ON = 1;
    T0CONbits.T08BIT = 1; // 8-bit timer
    T0CONbits.T0CS = 0; // use intOSC
    T0CONbits.PSA = 0; // use prescaler
    T0CONbits.T0PS = 2; // 1 => 1:4
    INTCONbits.T0IE = 1;
    INTCON2bits.TMR0IP = 0; // low priority

    T1CONbits.TMR1CS = 0; //Clock = Fosc/4
    T1CONbits.T1CKPS = 0; //PreScaler is 1:1
    T1CONbits.T1RD16 = 1; //Timer1=16bit timer
    T1CONbits.TMR1ON = 1; //enable
    IPR1bits.TMR1IP = 0; //low priority
    PIE1bits.TMR1IE = 1;

    TXSTA1bits.TX9 = 0; // 8-bit
    TXSTA1bits.TXEN = 1; //enable
    TXSTA1bits.SYNC = 0; // Asynchronous mode
    TXSTA1bits.BRGH = 0;
    RCSTA1bits.SPEN = 1; // Serial Port enable
    RCSTA1bits.RX9 = 0; // 8-bit
    RCSTA1bits.CREN = 1; // continuous receive enable
    BAUDCON1bits.BRG16 = 0; // use 8bit SPBRG
    SPBRG1 = 51;
    //IPR1bits.RC1IP = 0; //low priority
    //PIE1bits.RC1IE = 1;

    INTCONbits.PEIE = 1;
    INTCONbits.GIE = 0;

    uint8_t buf[255];
    ringbuf_init(&tx_buf, buf, sizeof (buf));

    uint8_t i;
    INTCONbits.GIE = 1;
    print(1);
    while (1) {
        if (cnt_sw > LONG_HOLD_LEVEL2)print_char = '\r';
        else if (cnt_sw > LONG_HOLD_LEVEL1)print_char = '\b';
        else print_char = PORTB;

        if (long_hold_flag1) {
            long_hold_flag1 = 0;
            tx_send('\b');
        }
        if (long_hold_flag2) {
            long_hold_flag2 = 0;
            tx_send('\r');
        }
        if (press_flag) {
            press_flag = 0;
            tx_send(PORTB);
        }
    }
    return 0;
}
Example #7
0
static void rx_wait(void)
{
  ef_request_id ids[EF_VI_TRANSMIT_BATCH];
  ef_event      evs[EF_VI_EVENT_POLL_MIN_EVS];
  int           n_ev, i;

  while( 1 ) {
    n_ev = ef_eventq_poll(&vi, evs, sizeof(evs) / sizeof(evs[0]));
    if( n_ev > 0 ) {
      for( i = 0; i < n_ev; ++i )
        switch( EF_EVENT_TYPE(evs[i]) ) {
        case EF_EVENT_TYPE_RX:
          TEST(EF_EVENT_RX_SOP(evs[i]) == 1);
          TEST(EF_EVENT_RX_CONT(evs[i]) == 0);
          TEST((int) (rx_posted - rx_completed) > 0);
          ++rx_completed;
          return;
        case EF_EVENT_TYPE_TX:
          ef_vi_transmit_unbundle(&vi, &evs[i], ids);
          break;
        case EF_EVENT_TYPE_RX_DISCARD:
          fprintf(stderr, "ERROR: RX_DISCARD type=%d\n",
                  EF_EVENT_RX_DISCARD_TYPE(evs[i]));
          break;
        case EF_EVENT_TYPE_TX_ERROR:
          fprintf(stderr, "ERROR: TX_ERROR type=%d\n",
                  EF_EVENT_TX_ERROR_TYPE(evs[i]));
          break;
        default:
          fprintf(stderr, "ERROR: unexpected event "EF_EVENT_FMT"\n",
                  EF_EVENT_PRI_ARG(evs[i]));
          break;
        }
    }
    else if( cfg_eventq_wait ) {
      TRY(ef_eventq_wait(&vi, driver_handle, ef_eventq_current(&vi), 0));
    }
    else if( cfg_fd_wait ) {
      TRY(ef_vi_prime(&vi, driver_handle, ef_eventq_current(&vi)));
      struct pollfd pollfd = {
        .fd      = driver_handle,
        .events  = POLLIN,
        .revents = 0,
      };
      TRY(poll(&pollfd, 1, -1));
    }
  }
}


static void tx_send(void)
{
  struct pkt_buf* pb = pkt_bufs[FIRST_TX_BUF];
  ef_vi_transmit(&vi, pb->dma_buf_addr, tx_frame_len, 0);
}

/**********************************************************************/

static void pong_test(void)
{
  int i;

  rx_post_8();

  for( i = 0; i < cfg_iter; ++i ) {
    rx_wait();
    tx_send();
    if( i % 8 == 0 )
      rx_post_8();
  }
}
void main(void) {
    OSCCON = 0b11110000; // 内部クロックは8MHzとする
    OPTION_REG = 0b00000000; // デジタルI/Oに内部プルアップ抵抗を使用する
    ANSELA = 0b00000000; // AN0-AN4は使用しない全てデジタルI/Oとする
    ANSELB = 0b00000000; // AN5-AN11は使用しない全てデジタルI/Oとする
    TRISA = 0b00000011; // ピン(RA)は全て出力に割当てる(RA5は入力のみとなる)
    TRISB = 0b00010110; // ピン(RB)はRB4(SCL1)/RB1(SDA1)のみ入力
    WPUB = 0b00010010; // RB1/4は内部プルアップ抵抗を指定する
    PORTA = 0b00000000; // RA出力ピンの初期化(全てLOWにする)
    PORTB = 0b00000000; // RB出力ピンの初期化(全てLOWにする)
    APFCON0bits.RXDTSEL = 1;
    APFCON1bits.TXCKSEL = 1;

    T1CON = 0x21; //Fosc/4, ps:1/4
    TMR1H = 0x00;
    TMR1L = 0x00;
    PIE1bits.TMR1IE = 1;

    I2C_init();
    LCD_init();
    UART_init(PIC16F1827);

    INTCONbits.PEIE = 1;
    INTCONbits.GIE = 1;

    uint8_t buf[70];
    ringbuf_init(&tx_buf, buf, sizeof (buf));

    RTC_Write(0x07, 0x00);

    while (1) {
        display();
        if (sw_RA1.flag.press) {
            sw_RA1.flag.press=0;
            tx_send('2');
            tx_send('0');
            tx_send(((YY & 0xF0) >> 4) + '0');
            tx_send((YY & 0x0F) + '0');
            tx_send('/');
            tx_send(((MM & 0xF0) >> 4) + '0');
            tx_send((MM & 0x0F) + '0');
            tx_send('/');
            tx_send(((DD & 0xF0) >> 4) + '0');
            tx_send((DD & 0x0F) + '0');
            tx_send('(');
            tx_send((EE & 0x0F) + '0');
            tx_send(')');
            tx_send(((hh & 0xF0) >> 4) + '0');
            tx_send((hh & 0x0F) + '0');
            tx_send(':');
            tx_send(((mm & 0xF0) >> 4) + '0');
            tx_send((mm & 0x0F) + '0');
            tx_send('-');
            tx_send(((ss & 0xF0) >> 4) + '0');
            tx_send((ss & 0x0F) + '0');
            tx_send('.');
            tx_send('\n');
            tx_sends("Real Time Clock\n");
        }
        if (sw_RA0.flag.long_holding_1) {
            sw_RA0.flag.long_holding_1 = 0;
            timeset(&YY, 0, 99, 0x06, 0, 0);
            timeset(&MM, 1, 12, 0x05, 3, 0);
            timeset(&DD, 1, month_length(YY, MM), 0x04, 6, 0);
            timeset(&hh, 0, 23, 0x02, 0, 1);
            timeset(&mm, 0, 59, 0x01, 3, 1);
            timeset(&ss, 0, 59, 0x00, 6, 1);
        }
    }