開発環境は、Cube suite+で、LCDはACM1602N1-FKW-FBW、マイコンは78K0R/KG3を使用しています。
以前こちらに質問させていただいたのですが、一種類だけですが、LCDに文字を表示させることができました。たとえば、「エ」だと、16個の「エ」が2行表示されます。次は、2種類以上の文字を表示させたいと思っています。プログラムの内容をあまり理解できておらず、なぜ16×2で表示されるのかもわかっていないのですが、それがどうしてなのか下のプログラムを見ていただいて教えていただけないでしょうか。重要なのは、while(1)の中身だと思います。IIC0 = 0b10110100;の2進数の部分を変えることで文字の種類を変えることができます。
#pragma sfr /* definition for using SFR */ #pragma NOP /* definition for using NOP */ void IIC_SMMIN(void); void IIC_SMMST(void); void IIC_SMMSP(void); /* 追加 */ void LCD_Init(void); void LCD_Comm(unsigned char comm_data); void MSDelay(unsigned int Milli_Sec); /*************************************************************************** * data definition ***************************************************************************/ unsigned char PCTXCT; /* counter of sending data */ unsigned char PCRXCT; /* 受counter of receiving data */ unsigned char PCRXDT; /* reception data buffer (1 byte) */ unsigned char PCRXBF[20]; /* reception data storage */ unsigned char PCTXSS; /* status flag 0: initial state 1: data sending 2: data receiving */ unsigned char PCADR; /* address setting (slave address + R/_W) */ #define D_IIC_SLV_ADR_W 0x0A0 /* slave address + W(0) */ #define D_IIC_SLV_ADR_R (0x0A0+0x1) /* slave address + R(1) */ #define D_IIC_SND_SIZE 0x1 /* number of data to send: 1 byte */ #define D_IIC_RCV_SIZE 0x2 /* number of data to receive: 2 bytes */ #define D_IIC_SND_DATA 0x0AA /* data to send */ /*************************************************************************** * Title: IIC0 Communication (Master Operation) * initial setting **************************************************************************** * Module: void IIC_SMMIN(void) * Arg: * Ret: ***************************************************************************/ void IIC_SMMIN(void) { IIC0EN = 1; /* supplies input clock */ /*追加*/ P6=0x03; PM6=0xFC; /************************************************** transfer clock setting */ IICX0 = 0x00; /* CLX0 = 0: no expansion */ IICCL0 = 0b00001010; /* CLD0=0: SCL0 pin was detected at low level DAD0=0: SDA0 pin was detected at low level SMC0=1: operates in fast mode DFC0=0: digital filter off CL01=1, CL00=0: transfer clock = fCLK/96 */ /************************************************** slave address setting (sets a local address when used as a master device) */ SVA0 = 0x00; /************************************************** sets start condition */ IICF0 = 0x00; /* STCF=0: clear STT0 (start condition) flag IICBSY=0: clear IICBSY (I2C bus status) flag STCEN=0: after operation is enabled (IICE0=1), enable generation of a start condition upon detection of s stop condition IICRSV=0: enable communication reservation */ /************************************************** IIC0 mode setting */ IICC0 = 0b00011100; /* IICE0=0: stop I2C operation LREL0=0: exit from communication: normal operation WREL0=0: do not cancel wait SPIE0=1: enable generation of interrupt request when stop condition is detected WTIM0=1: interrupt request is generated at the ninth clock's falling edge ACKE0=1: enable acknowledge STT0=0: do not generate a start condition SPT0=0: stop condition is not generated */ IICE0 = 1; /* enable operation */ /************************************************** port setting (after IICE0 = 1) */ P6 = 0b00000000; /* P61/SDA0 = low level P60/SCL0 = low level */ PM6.0 = 0; /* SCL0: output mode */ PM6.1 = 0; /* SDA0: output mode */ IICIF0 = 0; /* clear interrupt request flag (INTIIC0) */ if(STCEN == 1){ /* initial start enable trigger ? */ return; /* YES... */ } /************************************************** prepares for starting communication */ SPT0 = 1; /* generates a stop condition */ while(IICIF0 == 0){ /* INTIIC0 occurs? */ NOP(); } IICIF0 = 0; } /*************************************************************************** * Title: IIC0 Communication (Master Operation) * communication processing **************************************************************************** * Module: void IIC_SMMST(void) * Arg: * Ret: ***************************************************************************/ void IIC_SMMST(void) { PCTXCT = 0; /* clear counter of sending data */ PCRXCT = 0; /* clear counter of receiving data */ PCTXSS = 1; /* set status flag to 1 (data sending) */ LCD_Init(); while(1){ /************************************************** set slave address and transfer direction */ **STT0 = 1; /* スタートコンディション生成 generates start condition */ IIC0 = 0xA0; /* ,マスタ送信開始 send slave address and direction */ while(IICIF0 == 0){ /* INTIIC0 occurs? */ NOP(); } IICIF0 = 0; if(ACKD0 == 0){ /* ACK detected? */ goto JIC_SMMS10; } //STT0 = 1; IIC0 = 0x80; while(IICIF0 == 0){ NOP(); } IICIF0 = 0; if(ACKD0 == 0){ goto JIC_SMMS10; } //STT0 = 1; IIC0 = 0b10110100; while(IICIF0 == 0){ /* INTIIC0 occurs? */ NOP(); } IICIF0 = 0; if(ACKD0 == 0){ /* ACK detected? */ goto JIC_SMMS10; } //SPT0 = 1; /* while(IICIF0 == 0){ NOP(); } IICIF0 = 0; */ ** } /************************************************** restart */ /* Please add your program for restarting here. */ JIC_SMMS10: NOP(); NOP(); NOP(); IIC_SMMSP(); } /*************************************************************************** * Title: IIC0 Communication (Master Operation) * stops communication **************************************************************************** * Module: void IIC_SMMSP(void) * Arg: * Ret: ***************************************************************************/ void IIC_SMMSP(void) { SPT0 = 1; /* generates stop condition */ } void LCD_Init(void) { //MSDelay(15); //LCD_Comm( 0x01 ); //画面クリア //MSDelay(1); //NOP(); LCD_Comm( 0x38 ); //8ビットモード、2ライン、5x8ドット //MSDelay(1); NOP(); LCD_Comm( 0x0C ); //データ表示,2桁表示の設定 //MSDelay(1); //LCD_Comm( 0x06 ); //CURSOR移動、スクロールOFF NOP(); //LCD_Comm( 0x0f ); //ディスプレイON、CURSOR-ON、blinking-ON } void LCD_Comm( unsigned char comm_data ) { STT0 = 1; IIC0 = 0xA0; while(IICIF0 == 0){ /* INTIIC0 occurs? */ NOP(); } IICIF0 = 0; IIC0 = 0x00; //次バイトコマンド while(IICIF0 == 0){ /* INTIIC0 occurs? */ NOP(); } IICIF0 = 0; IIC0 = comm_data; //コマンドデータ while(IICIF0 == 0){ /* INTIIC0 occurs? */ NOP(); } IICIF0 = 0; //SPT0 = 1; /* stops communication */ } void MSDelay( unsigned int Milli_Sec ) { unsigned int x=0,y=0; for(x=0;x<Milli_Sec;x++) { for(y=0;y=3000;y++) { ; } } }
あなたの回答
tips
プレビュー