前回の最後の方で行ってたスケッチです。
見ての通り一部の文字しか対応していません(笑
これでおおよそ1500byteくらいです。
Attiny2313のフラッシュメモリが2000byteなので頑張れば移植できそうです。
ただポート番号が変わるのと、PCINTがBピンの並びにしかないので
使うならばINT割り込みになるんじゃないでしょうか。
(INT0はPD2、INT1はPD3)
LEDが9列なので少し見難い感はありますけど当初よりはスマートになったんじゃないかな?
以下。
#include<avr/io.h>
#include<avr/pgmspace.h>
#include<avr/interrupt.h>
#include<util/delay.h>
const prog_uint8_t a_line[2][6] = {{0b00000000,0b00000001,0b00000001,0b00000001,0b00000001,0b00000000},
{0b11111111,0b00001000,0b00001000,0b00001000,0b00001000,0b11111111}};
const prog_uint8_t b_line[2][6] = {{0b00000001,0b00000001,0b00000001,0b00000001,0b00000001,0b00000000},
{0b11111111,0b00010001,0b00010001,0b00010001,0b00010001,0b11101110}};
const prog_uint8_t d_line[2][6] = {{0b00000001,0b00000001,0b00000001,0b00000001,0b00000000,0b00000000},
{0b11111111,0b00000001,0b00000001,0b00000001,0b10000010,0b01111100}};
const prog_uint8_t e_line[2][6] = {{0b00000001,0b00000001,0b00000001,0b00000001,0b00000001,0b00000001},
{0b11111111,0b00010001,0b00010001,0b00010001,0b00010001,0b00000001}};
const prog_uint8_t h_line[2][6] = {{0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000001},
{0b11111111,0b00010000,0b00010000,0b00010000,0b00010000,0b11111111}};
const prog_uint8_t i_line[2][6] = {{0b00000001,0b00000001,0b00000001,0b00000001,0b00000001,0b00000001},
{0b00000001,0b00000001,0b11111111,0b00000001,0b00000001,0b00000001}};
const prog_uint8_t l_line[2][6] = {{0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},
{0b11111111,0b00000001,0b00000001,0b00000001,0b00000001,0b00000001}};
const prog_uint8_t m_line[2][6] = {{0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000001},
{0b11111111,0b11000000,0b01110000,0b01110000,0b11000000,0b11111111}};
const prog_uint8_t o_line[2][6] = {{0b00000000,0b00000001,0b00000001,0b00000001,0b00000001,0b00000000},
{0b11111110,0b00000001,0b00000001,0b00000001,0b00000001,0b11111110}};
const prog_uint8_t p_line[2][6] = {{0b00000001,0b00000001,0b00000001,0b00000001,0b00000001,0b00000000},
{0b11111111,0b00010000,0b00010000,0b00010000,0b00010000,0b11100000}};
const prog_uint8_t r_line[2][6] = {{0b00000001,0b00000001,0b00000001,0b00000001,0b00000001,0b00000000},
{0b11111111,0b00010000,0b00010000,0b00011000,0b00010100,0b11100011}};
const prog_uint8_t t_line[2][6] = {{0b00000001,0b00000001,0b00000001,0b00000001,0b00000001,0b00000001},
{0b00000000,0b00000000,0b11111111,0b00000000,0b00000000,0b00000000}};
const prog_uint8_t u_line[2][6] = {{0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000001},
{0b11111110,0b00000001,0b00000001,0b00000001,0b00000001,0b11111110}};
const prog_uint8_t v_line[2][6] = {{0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000001},
{0b11111000,0b00000110,0b00000001,0b00000001,0b00000110,0b11111000}};
const prog_uint8_t w_line[2][6] = {{0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000001},
{0b11111100,0b00000111,0b00111100,0b00111100,0b00000111,0b11111100}};
const prog_uint8_t y_line[2][6] = {{0b00000001,0b00000000,0b00000000,0b00000000,0b00000000,0b00000001},
{0b11000000,0b00100000,0b00011111,0b00010000,0b00100000,0b11000000}};
void space(){
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(30);
}
int main(void){
cli();
DDRB = 0b11111111;
DDRD = 0b11111111;
DDRC = 0b00000000;
PORTC = 0b11111111;
PCICR = (1<<PCIE1);
PCMSK1 = (1<<PCINT8);
int i;
sei();
while(1){
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&h_line[0][i]);
PORTD = pgm_read_byte(&h_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&a_line[0][i]);
PORTD = pgm_read_byte(&a_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&p_line[0][i]);
PORTD = pgm_read_byte(&p_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&p_line[0][i]);
PORTD = pgm_read_byte(&p_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&y_line[0][i]);
PORTD = pgm_read_byte(&y_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
space();
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&b_line[0][i]);
PORTD = pgm_read_byte(&b_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&i_line[0][i]);
PORTD = pgm_read_byte(&i_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&r_line[0][i]);
PORTD = pgm_read_byte(&r_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&t_line[0][i]);
PORTD = pgm_read_byte(&t_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&h_line[0][i]);
PORTD = pgm_read_byte(&h_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&d_line[0][i]);
PORTD = pgm_read_byte(&d_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&a_line[0][i]);
PORTD = pgm_read_byte(&a_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 6;i++){
PORTB = pgm_read_byte(&y_line[0][i]);
PORTD = pgm_read_byte(&y_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 0;i < 2;i++){
space();
}
}
}
ISR(PCINT1_vect){
if(bit_is_clear(PINC,PC0)){
_delay_ms(80);
int i;
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&d_line[0][i]);
PORTD = pgm_read_byte(&d_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&l_line[0][i]);
PORTD = pgm_read_byte(&l_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&r_line[0][i]);
PORTD = pgm_read_byte(&r_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&o_line[0][i]);
PORTD = pgm_read_byte(&o_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&w_line[0][i]);
PORTD = pgm_read_byte(&w_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
space();
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&o_line[0][i]);
PORTD = pgm_read_byte(&o_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&l_line[0][i]);
PORTD = pgm_read_byte(&l_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&l_line[0][i]);
PORTD = pgm_read_byte(&l_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&e_line[0][i]);
PORTD = pgm_read_byte(&e_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
for(i = 5;i >= 0;i--){
PORTB = pgm_read_byte(&h_line[0][i]);
PORTD = pgm_read_byte(&h_line[1][i]);
_delay_ms(3);
}
PORTB = 0b00000000;
PORTD = 0b00000000;
_delay_ms(3);
space();
}else{
}
}
0 件のコメント:
コメントを投稿