<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[forum.rcl-radio.ru &mdash; max7219 - 7 сегментный индикатор]]></title>
	<link rel="self" href="http://forum.rcl-radio.ru/extern.php?action=feed&amp;tid=295&amp;type=atom" />
	<updated>2021-04-08T09:36:04Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.rcl-radio.ru/viewtopic.php?id=295</id>
		<entry>
			<title type="html"><![CDATA[Re: max7219 - 7 сегментный индикатор]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=3399#p3399" />
			<content type="html"><![CDATA[<p>тест</p><div class="codebox"><pre><code>#define DIN PD2
#define CS  PD3
#define CLK PD4

void setup() {
  DDRD |= (1 &lt;&lt; DIN) | (1 &lt;&lt; CS) | (1 &lt;&lt; CLK);
  PORTD |= (1 &lt;&lt; CS);
  PORTD &amp;= ~(1 &lt;&lt; CLK) | (1 &lt;&lt; DIN);

  WriteBit16(0x0F,0x00); // Тест выкл.
  WriteBit16(0x0C,0x01); // Вкл. индик.
  WriteBit16(0x0B,0x07); // кол-во разрядов
  WriteBit16(0x09,0xFF); // Дешифраторы вкл.
  WriteBit16(0x0A,0x04); // яркость
}

void loop() {
  dec(12345678);
  }

void dec(long decimal){
  WriteBit16(0x08,decimal/10000000);
  WriteBit16(0x07,decimal/1000000%10);
  WriteBit16(0x06,decimal/100000%10);
  WriteBit16(0x05,decimal/10000%10);
  WriteBit16(0x04,decimal/1000%10);
  WriteBit16(0x03,decimal/100%10);
  WriteBit16(0x02,decimal/10%10);
  WriteBit16(0x01,decimal%10);
  }

void WriteBit16(byte reg, byte data){  
     PORTD &amp;= ~(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CS);
     for(int i = 7; i &gt;= 0; i--){
        if(((reg &gt;&gt; i) &amp; 1) == 1){PORTD |= (1 &lt;&lt; DIN);}else{PORTD &amp;= ~(1 &lt;&lt; DIN);}
        PORTD |=(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CLK);
        }
     for(int i = 7; i &gt;= 0; i--){
        if(((data &gt;&gt; i) &amp; 1) == 1){PORTD |= (1 &lt;&lt; DIN);}else{PORTD &amp;= ~(1 &lt;&lt; DIN);}
        PORTD |=(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CLK);
        }
     PORTD |=(1 &lt;&lt; CS);PORTD &amp;= ~(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; DIN);
  }  </code></pre></div>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-04-08T09:36:04Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=3399#p3399</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: max7219 - 7 сегментный индикатор]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=3398#p3398" />
			<content type="html"><![CDATA[<p>Attiny 2313 частотомер 9МГц</p><div class="codebox"><pre><code>#define DIN PD2
#define CS  PD3
#define CLK PD4
#define T1  PD5

volatile int x;
unsigned int timer0;
float f;
float pop_k = 0.996237;

void setup() {
  DDRD |= (1 &lt;&lt; DIN) | (1 &lt;&lt; CS) | (1 &lt;&lt; CLK);
  PORTD |= (1 &lt;&lt; CS);
  PORTD &amp;= ~(1 &lt;&lt; CLK) | (1 &lt;&lt; DIN);
  PORTD |= (1 &lt;&lt; T1);

  WriteBit16(0x0F,0x00); // Тест выкл.
  WriteBit16(0x0C,0x01); // Вкл. индик.
  WriteBit16(0x0B,0x07); // кол-во разрядов
  WriteBit16(0x09,0xFF); // Дешифраторы вкл.
  WriteBit16(0x0A,0x04); // яркость
     cli(); 
// TIMER1    
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1B = (1 &lt;&lt; CS12)|(1 &lt;&lt; CS11)|(1 &lt;&lt; CS10); 
  TIMSK |= (1 &lt;&lt; TOIE1); 
// TIMER0
  TCCR0A = 0;   
  TCCR0B = 0;   
  OCR0A = 250;
  TCCR0A |= (1 &lt;&lt; WGM01); 
  TCCR0B |= (1 &lt;&lt; CS01);  
  TIMSK |= (1 &lt;&lt; OCIE0A);  
   sei(); 
}

void loop() {}

void dec(long decimal){
  WriteBit16(0x08,15);
  WriteBit16(0x07,decimal/1000000%10+0x80);
  WriteBit16(0x06,decimal/100000%10);
  WriteBit16(0x05,decimal/10000%10);
  WriteBit16(0x04,decimal/1000%10+0x80);
  WriteBit16(0x03,decimal/100%10);
  WriteBit16(0x02,decimal/10%10);
  WriteBit16(0x01,decimal%10);
  }

void WriteBit16(byte reg, byte data){  
     PORTD &amp;= ~(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CS);
     for(int i = 7; i &gt;= 0; i--){
        if(((reg &gt;&gt; i) &amp; 1) == 1){PORTD |= (1 &lt;&lt; DIN);}else{PORTD &amp;= ~(1 &lt;&lt; DIN);}
        PORTD |=(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CLK);
        }
     for(int i = 7; i &gt;= 0; i--){
        if(((data &gt;&gt; i) &amp; 1) == 1){PORTD |= (1 &lt;&lt; DIN);}else{PORTD &amp;= ~(1 &lt;&lt; DIN);}
        PORTD |=(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CLK);
        }
     PORTD |=(1 &lt;&lt; CS);PORTD &amp;= ~(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; DIN);
  }  


ISR(TIMER0_COMPA_vect){
    timer0++;
  if(timer0 == 1){
    x = 0;TCNT1 = 0;
     TCCR1B = (1 &lt;&lt; CS12)|(1 &lt;&lt; CS11)|(1 &lt;&lt; CS10);}
  if(timer0 == 10001){
     TCCR1B &amp;= ~(1 &lt;&lt; CS12)|(1 &lt;&lt; CS11)|(1 &lt;&lt; CS10); 
     f = ((x * 65535) + TCNT1)*pop_k; dec(f); timer0 = 0; }
  }  

ISR (TIMER1_OVF_vect){x++;}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-04-08T09:29:48Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=3398#p3398</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[max7219 - 7 сегментный индикатор]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=3397#p3397" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>#define DIN PD2
#define CS  PD3
#define CLK PD4

long x;

void setup() {
  DDRD |= (1 &lt;&lt; DIN) | (1 &lt;&lt; CS) | (1 &lt;&lt; CLK);
  PORTD |= (1 &lt;&lt; CS);
  PORTD &amp;= ~(1 &lt;&lt; CLK) | (1 &lt;&lt; DIN);
  delay(1);

  WriteBit16(0x0F,0x00); // Тест выкл.
  WriteBit16(0x0C,0x01); // Вкл. индик.
  WriteBit16(0x0B,0x07); // кол-во разрядов
  WriteBit16(0x09,0xFF); // Дешифраторы вкл.
  WriteBit16(0x0A,0x00); // яркость
}

void loop() {

  dec(x++); 
delay(100);
}

void dec(long decimal){
  WriteBit16(0x08,decimal/10000000);
  WriteBit16(0x07,decimal/1000000%10);
  WriteBit16(0x06,decimal/100000%10);
  WriteBit16(0x05,decimal/10000%10);
  WriteBit16(0x04,decimal/1000%10);
  WriteBit16(0x03,decimal/100%10);
  WriteBit16(0x02,decimal/10%10);
  WriteBit16(0x01,decimal%10);
  }

void WriteBit16(byte reg, byte data){  
     PORTD &amp;= ~(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CS);
     for(int i = 7; i &gt;= 0; i--){
        if(((reg &gt;&gt; i) &amp; 1) == 1){PORTD |= (1 &lt;&lt; DIN);}else{PORTD &amp;= ~(1 &lt;&lt; DIN);}
        PORTD |=(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CLK);
        }
     for(int i = 7; i &gt;= 0; i--){
        if(((data &gt;&gt; i) &amp; 1) == 1){PORTD |= (1 &lt;&lt; DIN);}else{PORTD &amp;= ~(1 &lt;&lt; DIN);}
        PORTD |=(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; CLK);
        }
     PORTD |=(1 &lt;&lt; CS);PORTD &amp;= ~(1 &lt;&lt; CLK);PORTD &amp;= ~(1 &lt;&lt; DIN);
  }  </code></pre></div>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-04-08T00:13:42Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=3397#p3397</id>
		</entry>
</feed>
