/************************************************/ /* FILE :Max II VRAM.c */ /* DATE :2005/02/08 */ /* DESCRIPTION :Main Program */ /* CPU TYPE :16F873 */ /* : */ /************************************************/ #include <16f873.h> #fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT #use delay(CLOCK=20000000) #use rs232(BAUD=38400,XMIT=PIN_C6,RCV=PIN_C7) #use fast_io(A) #use fast_io(B) #use fast_io(C) /// 変数宣言 int32 i; int8 RxD,R,G,B; //;***** PIC16F873SP Package Pin Assign ******************************** //; +---u---+ //;/MCLR --|01 28|-- --- PortA RA0: //; --|02 27|-- --- RA1: //; --|03 26|-- --- RA2: //; -|04 25|-- --- RA3: --- //; --- --|05 24|-- --- RA4: --- //; --- --|06 23|-- --- RA5: --- //; --- --|07 22|-- A1 PortB RB0: A0 //; VSS --|08 21|-- A0 RB1: A1 //;CK20M --|09 20|-- VDD RB2: --- //; --|10 19|-- VSS RB3: --- //; CS --|11 18|-- RXD RB4: --- //; DRDY --|12 17|-- TXD RB5: --- //; DSYNC--|13 16|-- SDO RB6: --- //; SCLK --|14 15|-- SDI RB7: --- //; +-------+ PortC RC0: CS //; RC1: DRDY //; RC2: DSYNC //; RC3: SCLK //; RC4: SDI //; RC5: SDO //; RC6: RS-232c_TxD //; RC7: RS-232c_RxD /// ポートの設定 /****************************************/ /* PORTA o, o, o, o, o, o, o, o /* ---,---,RA5,RA4,RA3,RA2,RA1,RA0 /* PORTB i, i, i, i, i, i, i, i, /* RB7,RB6,RB5,RB4,RB3,RB2,RB1,RB0 /* PORTC i, o, i, i, i, i, i, o /* rxd,txd,sdo,sdi,sck,RC2,RC1,RC0 /****************************************/ void iniMM() { output_low(PIN_A1); output_low(PIN_A2); delay_us(5); output_low(PIN_A5); delay_us(5); output_high(PIN_A5); delay_us(5); set_tris_b(0x00); } void stb() { delay_us(5); output_low(PIN_A0); delay_us(2); output_high(PIN_A0); output_low(PIN_A3); delay_us(2); output_high(PIN_A3); } void closeMM() { set_tris_b(0xFF); delay_us(1); output_high(PIN_A1); delay_us(1); output_high(PIN_A2); } void ScreenInitialize() { R=0xFF; G=0x00; B=0x00; iniMM(); for (i=0; i<30000; i++) /* 400*600/8=30000 */ { output_b(R); stb(); output_b(G); stb(); output_b(B); stb(); } closeMM(); delay_ms(3000); /* 3秒wait */ R=0x00; G=0xFF; B=0x00; iniMM(); for (i=0; i<30000; i++) /* 400*600/8=30000 */ { output_b(R); stb(); output_b(G); stb(); output_b(B); stb(); } closeMM(); delay_ms(3000); /* 3秒wait */ R=0x00; G=0x00; B=0xFF; iniMM(); for (i=0; i<30000; i++) /* 400*600/8=30000 */ { output_b(R); stb(); output_b(G); stb(); output_b(B); stb(); } closeMM(); } /// メイン関数 void main () { port_b_pullups(FALSE); output_a(0x3F); set_tris_a(0x00); set_tris_b(0xFF); output_c(0x00); set_tris_c(0xBE); /* RESET=L */ ////割込み許可 disable_interrupts(INT_RDA); //USART 受信割込み許可 disable_interrupts(GLOBAL); //割込み許可 delay_ms(100); output_high(PIN_C0); /* RESET=H */ ScreenInitialize(); /* printf("Ready"); */ L1: RxD=getc(); switch(RxD) { case 0x00: ScreenInitialize(); break; case 0x01: iniMM(); for (i=0; i<30000; i++) { RxD=getc(); output_b(RxD); stb(); RxD=getc(); output_b(RxD); stb(); RxD=getc(); output_b(RxD); stb(); } closeMM(); break; } goto L1; }