0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

H8/3664ではじめるマイコン制御3 7segLED-Rotation

Last updated at Posted at 2019-01-06

今回はビットシフトを用いて二つの7segLEDの外周を順に点灯させていくプログラムです。

7segRotation.c

//7segLEDの外周を順に点灯させ1の位で一周すると10の位で1つ移動するプログラム
# include <stdio.h>

# define	BRR		(*((unsigned char *)0xFFA9))
# define	TMA		(*((unsigned char *)0xFFA6))

# define	PMR1	(*((unsigned char *)0xFFE0))
# define	PMR5	(*((unsigned char *)0xFFE1))

# define	PCR1	(*((unsigned char *)0xFFE4))
# define	PCR5	(*((unsigned char *)0xFFE8))
# define	PCR7	(*((unsigned char *)0xFFEA))
# define	PCR8	(*((unsigned char *)0xFFEB))

# define	PDR5	(*((unsigned char *)0xFFD8))
# define	PDR7	(*((unsigned char *)0xFFDA))
void wait();

main()
   {
	int i,cnt=1;
	unsigned char Seg1,Seg10;//表示用変数
	unsigned char rot;//1の位シフト用
	unsigned char rot10;//10の位シフト用
	
	BRR=12;			//16MHZ時には12を デフォルトは7 ボーレート変更	
 	PMR1 = 0x00;			/*ポート1を汎用IOに設定*/
 	PMR5 = 0x00;			/*ポート1を汎用IOに設定*/

	TMA = 0x98 ; 

 	PCR1 = 0xff;	//アドレス FFE4
    PCR5 = 0xff;	//FFE8
    PCR7 = 0x00;	
    PCR8 = 0xff;	//FFED		//00入力  ff出力
    
    
    if(cnt==1){//初期化
		Seg1=0x01;Seg10=0x81;rot=0x01;rot10=0x81;cnt=0;
		}
		
		
    for (;;) {/* 無限ループ */
		    
		
		wait(2000);
		PDR5=Seg1;
		wait(2000);
		PDR5=Seg10;
		wait(2000);
		
		
		if(rot==0x40){//1の位が1周したときの条件文
			rot=0x01;
			Seg1=rot;
			rot=rot<<1;
			
			//10の位のシフト
			rot10=rot10<<1;
			rot10=rot10 | 0x80;
			Seg10=rot10;
			}
		else{
			Seg1=rot;
			rot=rot<<1;
			}

		if(rot10==0xC0){//10の位が1周したときの条件文
		rot10=0x81;
		Seg10=rot10;
		}
		else{}
				
    }
    return 0;
   }

void wait(int n)
{
	int i;
 	for(i=0;i<n;i++);
}

image.png
以前にも述べましたが7segLEDは上図のようなビットとの対応をしているので、順にAから順に左シフトさせていくことで外周を順に点灯させていくことができます。そしてFを点灯後Gを飛ばしてAへ戻るようにします。

次へ H8/3664ではじめるマイコン制御4

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?