/* 32 x 16 Dot LED DEMO*/ #include "18F26K22.H" #fuses INTRC_IO,NOWDT,NOMCLR,NOBROWNOUT,NOLVP,PUT #use delay(internal=64MHz) #define SIN_1 PIN_B0 // COMMON #define SIN_2 PIN_B1 // COLUM A #define SIN_3 PIN_B2 // COLUM B #define CLOCK PIN_B3 #define LATCH PIN_B4 #define ENABLE PIN_B5 union { int32 pint32; int16 pint16[2]; } pat_buf[16]; // LED PATTERN BUFFER void led_dataout(int16 s1,int16 s2,int16 s3) { int i; for(i=0;i<16;i++){ if(s1&0x8000) output_high(SIN_1); else output_low(SIN_1); if(s2&0x8000) output_high(SIN_2); else output_low(SIN_2); if(s3&0x8000) output_high(SIN_3); else output_low(SIN_3); s1 = s1 << 1; output_high(CLOCK); s2 = s2 << 1; s3 = s3 << 1; output_low(CLOCK); } output_high(LATCH); delay_cycles(1); output_low(LATCH); } #INT_RTCC rtcc_isr() // interrupt every 1.024ms { static int line = 0; int16 com = 0; int16 s1,s2; bit_set(com,line); s1 = pat_buf[line].pint16[0]; s2 = pat_buf[line].pint16[1]; led_dataout(com,s1,s2); line++; line &= 15; } void main() { int i,j; setup_oscillator(OSC_64MHZ); output_drive(SIN_1); output_drive(SIN_2); output_drive(SIN_3); output_drive(PIN_C4); output_low(CLOCK); output_drive(CLOCK); output_low(LATCH); output_drive(LATCH); output_low(ENABLE); output_drive(ENABLE); delay_ms(100); setup_timer_0(T0_INTERNAL | T0_DIV_64 | T0_8_BIT); /* タイマー間隔は 1.024ms 8 Bit mode */ enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); pat_buf[ 0]=0b00000000000011000000000000000011; pat_buf[ 1]=0b00000000000110000000000000000110; pat_buf[ 2]=0b00000000001100000000000000001100; pat_buf[ 3]=0b00000000011000000000000000011000; pat_buf[ 4]=0b00000000110000000000000000110000; pat_buf[ 5]=0b00000001100000000000000001100000; pat_buf[ 6]=0b00000011000000000000000011000000; pat_buf[ 7]=0b00000110000000000000000110000000; pat_buf[ 8]=0b00000110000000000000000110000000; pat_buf[ 9]=0b00000011000000000000000011000000; pat_buf[10]=0b00000001100000000000000001100000; pat_buf[11]=0b00000000110000000000000000110000; pat_buf[12]=0b00000000011000000000000000011000; pat_buf[13]=0b00000000001100000000000000001100; pat_buf[14]=0b00000000000110000000000000000110; pat_buf[15]=0b00000000000011000000000000000011; while(1){ for(i=0;i<16;i++){ // SHIFT PATTERN if(pat_buf[i].pint32 & 0x80000000) j=1; else j=0; pat_buf[i].pint32 = pat_buf[i].pint32 << 1; if(j) pat_buf[i].pint32 |= 1; } delay_ms(25); } }