Combined LED and switch matrix...

Go To Last Post
57 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everyone; I appreciate the help!!! :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agree that the bitfield version is more readable, but it compiles longer.  25514 vs 25598 bytes flash.  Here is the LSS from the bitfield version (45 lines longer):

 

    //lampboard and keyboard
    if (BrightTimer==ThisBright)
    5546:	90 91 22 01 	lds	r25, 0x0122	; 0x800122 <BrightTimer.3756>
    554a:	80 91 21 01 	lds	r24, 0x0121	; 0x800121 <ThisBright.3757>
    554e:	98 13       	cpse	r25, r24
    5550:	03 c0       	rjmp	.+6      	; 0x5558 <__vector_16+0xd6>
      {
        //disable rows
        DDR(LAMPBOARD_PORT)&=~(_BV(LAMPBOARD_ROW0_PIN) | _BV(LAMPBOARD_ROW1_PIN) | _BV(LAMPBOARD_ROW2_PIN) | _BV(LAMPBOARD_ROW3_PIN) | _BV(LAMPBOARD_ROW4_PIN) | _BV(LAMPBOARD_ROW5_PIN));
    5552:	87 b1       	in	r24, 0x07	; 7
    5554:	83 70       	andi	r24, 0x03	; 3
    5556:	87 b9       	out	0x07, r24	; 7
      }

    BrightTimer++;
    5558:	80 91 22 01 	lds	r24, 0x0122	; 0x800122 <BrightTimer.3756>
    555c:	8f 5f       	subi	r24, 0xFF	; 255
    555e:	80 93 22 01 	sts	0x0122, r24	; 0x800122 <BrightTimer.3756>
    if (BrightTimer==LAMPBOARD_BRIGHT_LEVELS)
    5562:	88 30       	cpi	r24, 0x08	; 8
    5564:	09 f0       	breq	.+2      	; 0x5568 <__vector_16+0xe6>
    5566:	e8 c1       	rjmp	.+976    	; 0x5938 <__vector_16+0x4b6>
      {
        //keyboard input

        //columns input with pullup
        LBKBSHARED_PORT|=_BV(LBKBSHARED_COL0_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL4_PIN);
    5568:	8b b1       	in	r24, 0x0b	; 11
    556a:	88 6f       	ori	r24, 0xF8	; 248
    556c:	8b b9       	out	0x0b, r24	; 11
        DDR(LBKBSHARED_PORT)&=~(_BV(LBKBSHARED_COL0_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL4_PIN));
    556e:	8a b1       	in	r24, 0x0a	; 10
    5570:	87 70       	andi	r24, 0x07	; 7
    5572:	8a b9       	out	0x0a, r24	; 10
        //76543210 76543210 76543210 76543210
        // 0000011 11122222 33333444 4455555s

        #define SETTLE_DELAY 8

        switch(Row)
    5574:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    5578:	82 30       	cpi	r24, 0x02	; 2
    557a:	09 f4       	brne	.+2      	; 0x557e <__vector_16+0xfc>
    557c:	68 c0       	rjmp	.+208    	; 0x564e <__vector_16+0x1cc>
    557e:	28 f4       	brcc	.+10     	; 0x558a <__vector_16+0x108>
    5580:	88 23       	and	r24, r24
    5582:	51 f0       	breq	.+20     	; 0x5598 <__vector_16+0x116>
    5584:	81 30       	cpi	r24, 0x01	; 1
    5586:	71 f1       	breq	.+92     	; 0x55e4 <__vector_16+0x162>
    5588:	db c0       	rjmp	.+438    	; 0x5740 <__vector_16+0x2be>
    558a:	83 30       	cpi	r24, 0x03	; 3
    558c:	09 f4       	brne	.+2      	; 0x5590 <__vector_16+0x10e>
    558e:	7d c0       	rjmp	.+250    	; 0x568a <__vector_16+0x208>
    5590:	84 30       	cpi	r24, 0x04	; 4
    5592:	09 f4       	brne	.+2      	; 0x5596 <__vector_16+0x114>
    5594:	a0 c0       	rjmp	.+320    	; 0x56d6 <__vector_16+0x254>
    5596:	d4 c0       	rjmp	.+424    	; 0x5740 <__vector_16+0x2be>
          {
            case 0:
              //row 0
              DDR(KEYBOARD_PORT)|=_BV(KEYBOARD_ROW0_PIN);
    5598:	08 9a       	sbi	0x01, 0	; 1
              //__builtin_avr_delay_cycles(SETTLE_DELAY);

              //these 3 lines here on purpose to use cpu cycles
              BrightTimer=0;
    559a:	10 92 22 01 	sts	0x0122, r1	; 0x800122 <BrightTimer.3756>
              ThisBright=((Dimmed)?0:Configuration.LampboardBright);
    559e:	90 91 1f 01 	lds	r25, 0x011F	; 0x80011f <Dimmed.3762>
    55a2:	91 11       	cpse	r25, r1
    55a4:	02 c0       	rjmp	.+4      	; 0x55aa <__vector_16+0x128>
    55a6:	80 91 c5 01 	lds	r24, 0x01C5	; 0x8001c5 <Configuration>
    55aa:	80 93 21 01 	sts	0x0121, r24	; 0x800121 <ThisBright.3757>
              Row++;
    55ae:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    55b2:	8f 5f       	subi	r24, 0xFF	; 255
    55b4:	80 93 20 01 	sts	0x0120, r24	; 0x800120 <Row.3755>

              AInput.row0=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 3;
    55b8:	89 b1       	in	r24, 0x09	; 9
    55ba:	90 e0       	ldi	r25, 0x00	; 0
    55bc:	80 95       	com	r24
    55be:	90 95       	com	r25
    55c0:	88 7f       	andi	r24, 0xF8	; 248
    55c2:	99 27       	eor	r25, r25
    55c4:	e3 e0       	ldi	r30, 0x03	; 3
    55c6:	95 95       	asr	r25
    55c8:	87 95       	ror	r24
    55ca:	ea 95       	dec	r30
    55cc:	e1 f7       	brne	.-8      	; 0x55c6 <__vector_16+0x144>
    55ce:	8f 71       	andi	r24, 0x1F	; 31
    55d0:	98 2f       	mov	r25, r24
    55d2:	99 0f       	add	r25, r25
    55d4:	80 91 1b 01 	lds	r24, 0x011B	; 0x80011b <AInput.3782>
    55d8:	81 7c       	andi	r24, 0xC1	; 193
    55da:	89 2b       	or	r24, r25
    55dc:	80 93 1b 01 	sts	0x011B, r24	; 0x80011b <AInput.3782>
              //((uint8_t*)&AInput)[0]=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 1;
              DDR(KEYBOARD_PORT)&=~_BV(KEYBOARD_ROW0_PIN);
    55e0:	08 98       	cbi	0x01, 0	; 1
              break;
    55e2:	db c0       	rjmp	.+438    	; 0x579a <__vector_16+0x318>

            case 1:
              //row 1
              DDR(KEYBOARD_PORT)|=_BV(KEYBOARD_ROW1_PIN);
    55e4:	09 9a       	sbi	0x01, 1	; 1
              //__builtin_avr_delay_cycles(SETTLE_DELAY);

              //these 3 lines here on purpose to use cpu cycles
              BrightTimer=0;
    55e6:	10 92 22 01 	sts	0x0122, r1	; 0x800122 <BrightTimer.3756>
              ThisBright=((Dimmed)?0:Configuration.LampboardBright);
    55ea:	80 91 1f 01 	lds	r24, 0x011F	; 0x80011f <Dimmed.3762>
    55ee:	81 11       	cpse	r24, r1
    55f0:	03 c0       	rjmp	.+6      	; 0x55f8 <__vector_16+0x176>
    55f2:	80 91 c5 01 	lds	r24, 0x01C5	; 0x8001c5 <Configuration>
    55f6:	01 c0       	rjmp	.+2      	; 0x55fa <__vector_16+0x178>
    55f8:	80 e0       	ldi	r24, 0x00	; 0
    55fa:	80 93 21 01 	sts	0x0121, r24	; 0x800121 <ThisBright.3757>
              Row++;
    55fe:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    5602:	8f 5f       	subi	r24, 0xFF	; 255
    5604:	80 93 20 01 	sts	0x0120, r24	; 0x800120 <Row.3755>

              AInput.row1=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 3;
    5608:	89 b1       	in	r24, 0x09	; 9
    560a:	90 e0       	ldi	r25, 0x00	; 0
    560c:	80 95       	com	r24
    560e:	90 95       	com	r25
    5610:	88 7f       	andi	r24, 0xF8	; 248
    5612:	99 27       	eor	r25, r25
    5614:	63 e0       	ldi	r22, 0x03	; 3
    5616:	95 95       	asr	r25
    5618:	87 95       	ror	r24
    561a:	6a 95       	dec	r22
    561c:	e1 f7       	brne	.-8      	; 0x5616 <__vector_16+0x194>
    561e:	38 2f       	mov	r19, r24
    5620:	32 95       	swap	r19
    5622:	33 0f       	add	r19, r19
    5624:	33 0f       	add	r19, r19
    5626:	30 7c       	andi	r19, 0xC0	; 192
    5628:	20 91 1b 01 	lds	r18, 0x011B	; 0x80011b <AInput.3782>
    562c:	2f 73       	andi	r18, 0x3F	; 63
    562e:	23 2b       	or	r18, r19
    5630:	20 93 1b 01 	sts	0x011B, r18	; 0x80011b <AInput.3782>
    5634:	96 95       	lsr	r25
    5636:	87 95       	ror	r24
    5638:	96 95       	lsr	r25
    563a:	87 95       	ror	r24
    563c:	87 70       	andi	r24, 0x07	; 7
    563e:	90 91 1c 01 	lds	r25, 0x011C	; 0x80011c <AInput.3782+0x1>
    5642:	98 7f       	andi	r25, 0xF8	; 248
    5644:	89 2b       	or	r24, r25
    5646:	80 93 1c 01 	sts	0x011C, r24	; 0x80011c <AInput.3782+0x1>
              //((uint8_t*)&AInput)[0]|=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN))) >> 6;
              //((uint8_t*)&AInput)[1]=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) << 2;
              DDR(KEYBOARD_PORT)&=~_BV(KEYBOARD_ROW1_PIN);
    564a:	09 98       	cbi	0x01, 1	; 1
              break;
    564c:	a6 c0       	rjmp	.+332    	; 0x579a <__vector_16+0x318>

            case 2:
              //row 2
              DDR(KEYBOARD_PORT)|=_BV(KEYBOARD_ROW2_PIN);
    564e:	0a 9a       	sbi	0x01, 2	; 1
              //__builtin_avr_delay_cycles(SETTLE_DELAY);

              //these 3 lines here on purpose to use cpu cycles
              BrightTimer=0;
    5650:	10 92 22 01 	sts	0x0122, r1	; 0x800122 <BrightTimer.3756>
              ThisBright=((Dimmed)?0:Configuration.LampboardBright);
    5654:	80 91 1f 01 	lds	r24, 0x011F	; 0x80011f <Dimmed.3762>
    5658:	81 11       	cpse	r24, r1
    565a:	03 c0       	rjmp	.+6      	; 0x5662 <__vector_16+0x1e0>
    565c:	80 91 c5 01 	lds	r24, 0x01C5	; 0x8001c5 <Configuration>
    5660:	01 c0       	rjmp	.+2      	; 0x5664 <__vector_16+0x1e2>
    5662:	80 e0       	ldi	r24, 0x00	; 0
    5664:	80 93 21 01 	sts	0x0121, r24	; 0x800121 <ThisBright.3757>
              Row++;
    5668:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    566c:	8f 5f       	subi	r24, 0xFF	; 255
    566e:	80 93 20 01 	sts	0x0120, r24	; 0x800120 <Row.3755>

              AInput.row2=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 3;
    5672:	89 b1       	in	r24, 0x09	; 9
    5674:	80 95       	com	r24
    5676:	98 2f       	mov	r25, r24
    5678:	98 7f       	andi	r25, 0xF8	; 248
    567a:	80 91 1c 01 	lds	r24, 0x011C	; 0x80011c <AInput.3782+0x1>
    567e:	87 70       	andi	r24, 0x07	; 7
    5680:	89 2b       	or	r24, r25
    5682:	80 93 1c 01 	sts	0x011C, r24	; 0x80011c <AInput.3782+0x1>
              //((uint8_t*)&AInput)[1]|=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 3;
              DDR(KEYBOARD_PORT)&=~_BV(KEYBOARD_ROW2_PIN);
    5686:	0a 98       	cbi	0x01, 2	; 1
              break;
    5688:	88 c0       	rjmp	.+272    	; 0x579a <__vector_16+0x318>

            case 3:
              //row 3
              DDR(KEYBOARD_PORT)|=_BV(KEYBOARD_ROW3_PIN);
    568a:	0b 9a       	sbi	0x01, 3	; 1
              //__builtin_avr_delay_cycles(SETTLE_DELAY);

              //these 3 lines here on purpose to use cpu cycles
              BrightTimer=0;
    568c:	10 92 22 01 	sts	0x0122, r1	; 0x800122 <BrightTimer.3756>
              ThisBright=((Dimmed)?0:Configuration.LampboardBright);
    5690:	80 91 1f 01 	lds	r24, 0x011F	; 0x80011f <Dimmed.3762>
    5694:	81 11       	cpse	r24, r1
    5696:	03 c0       	rjmp	.+6      	; 0x569e <__vector_16+0x21c>
    5698:	80 91 c5 01 	lds	r24, 0x01C5	; 0x8001c5 <Configuration>
    569c:	01 c0       	rjmp	.+2      	; 0x56a0 <__vector_16+0x21e>
    569e:	80 e0       	ldi	r24, 0x00	; 0
    56a0:	80 93 21 01 	sts	0x0121, r24	; 0x800121 <ThisBright.3757>
              Row++;
    56a4:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    56a8:	8f 5f       	subi	r24, 0xFF	; 255
    56aa:	80 93 20 01 	sts	0x0120, r24	; 0x800120 <Row.3755>

              AInput.row3=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 3;
    56ae:	89 b1       	in	r24, 0x09	; 9
    56b0:	90 e0       	ldi	r25, 0x00	; 0
    56b2:	80 95       	com	r24
    56b4:	90 95       	com	r25
    56b6:	88 7f       	andi	r24, 0xF8	; 248
    56b8:	99 27       	eor	r25, r25
    56ba:	53 e0       	ldi	r21, 0x03	; 3
    56bc:	95 95       	asr	r25
    56be:	87 95       	ror	r24
    56c0:	5a 95       	dec	r21
    56c2:	e1 f7       	brne	.-8      	; 0x56bc <__vector_16+0x23a>
    56c4:	8f 71       	andi	r24, 0x1F	; 31
    56c6:	90 91 1d 01 	lds	r25, 0x011D	; 0x80011d <AInput.3782+0x2>
    56ca:	90 7e       	andi	r25, 0xE0	; 224
    56cc:	89 2b       	or	r24, r25
    56ce:	80 93 1d 01 	sts	0x011D, r24	; 0x80011d <AInput.3782+0x2>
              //((uint8_t*)&AInput)[2]=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN)));
              DDR(KEYBOARD_PORT)&=~_BV(KEYBOARD_ROW3_PIN);
    56d2:	0b 98       	cbi	0x01, 3	; 1
              break;
    56d4:	62 c0       	rjmp	.+196    	; 0x579a <__vector_16+0x318>

            case 4:
              //row 4
              DDR(KEYBOARD_PORT)|=_BV(KEYBOARD_ROW4_PIN);
    56d6:	0c 9a       	sbi	0x01, 4	; 1
              //__builtin_avr_delay_cycles(SETTLE_DELAY);

              //these 3 lines here on purpose to use cpu cycles
              BrightTimer=0;
    56d8:	10 92 22 01 	sts	0x0122, r1	; 0x800122 <BrightTimer.3756>
              ThisBright=((Dimmed)?0:Configuration.LampboardBright);
    56dc:	80 91 1f 01 	lds	r24, 0x011F	; 0x80011f <Dimmed.3762>
    56e0:	81 11       	cpse	r24, r1
    56e2:	03 c0       	rjmp	.+6      	; 0x56ea <__vector_16+0x268>
    56e4:	80 91 c5 01 	lds	r24, 0x01C5	; 0x8001c5 <Configuration>
    56e8:	01 c0       	rjmp	.+2      	; 0x56ec <__vector_16+0x26a>
    56ea:	80 e0       	ldi	r24, 0x00	; 0
    56ec:	80 93 21 01 	sts	0x0121, r24	; 0x800121 <ThisBright.3757>
              Row++;
    56f0:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    56f4:	8f 5f       	subi	r24, 0xFF	; 255
    56f6:	80 93 20 01 	sts	0x0120, r24	; 0x800120 <Row.3755>

              AInput.row4=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 3;
    56fa:	89 b1       	in	r24, 0x09	; 9
    56fc:	90 e0       	ldi	r25, 0x00	; 0
    56fe:	80 95       	com	r24
    5700:	90 95       	com	r25
    5702:	88 7f       	andi	r24, 0xF8	; 248
    5704:	99 27       	eor	r25, r25
    5706:	33 e0       	ldi	r19, 0x03	; 3
    5708:	95 95       	asr	r25
    570a:	87 95       	ror	r24
    570c:	3a 95       	dec	r19
    570e:	e1 f7       	brne	.-8      	; 0x5708 <__vector_16+0x286>
    5710:	38 2f       	mov	r19, r24
    5712:	32 95       	swap	r19
    5714:	33 0f       	add	r19, r19
    5716:	30 7e       	andi	r19, 0xE0	; 224
    5718:	20 91 1d 01 	lds	r18, 0x011D	; 0x80011d <AInput.3782+0x2>
    571c:	2f 71       	andi	r18, 0x1F	; 31
    571e:	23 2b       	or	r18, r19
    5720:	20 93 1d 01 	sts	0x011D, r18	; 0x80011d <AInput.3782+0x2>
    5724:	43 e0       	ldi	r20, 0x03	; 3
    5726:	96 95       	lsr	r25
    5728:	87 95       	ror	r24
    572a:	4a 95       	dec	r20
    572c:	e1 f7       	brne	.-8      	; 0x5726 <__vector_16+0x2a4>
    572e:	83 70       	andi	r24, 0x03	; 3
    5730:	90 91 1e 01 	lds	r25, 0x011E	; 0x80011e <AInput.3782+0x3>
    5734:	9c 7f       	andi	r25, 0xFC	; 252
    5736:	89 2b       	or	r24, r25
    5738:	80 93 1e 01 	sts	0x011E, r24	; 0x80011e <AInput.3782+0x3>
              //((uint8_t*)&AInput)[2]|=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN))) >> 5;
              //((uint8_t*)&AInput)[3]=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) << 3;
              DDR(KEYBOARD_PORT)&=~_BV(KEYBOARD_ROW4_PIN);
    573c:	0c 98       	cbi	0x01, 4	; 1
              break;
    573e:	2d c0       	rjmp	.+90     	; 0x579a <__vector_16+0x318>

            default:
            //case 5:
              //row 5
              DDR(KEYBOARD_PORT)|=_BV(KEYBOARD_ROW5_PIN);
    5740:	0d 9a       	sbi	0x01, 5	; 1
              //__builtin_avr_delay_cycles(SETTLE_DELAY);

              //these 3 lines here on purpose to use cpu cycles
              BrightTimer=0;
    5742:	10 92 22 01 	sts	0x0122, r1	; 0x800122 <BrightTimer.3756>
              ThisBright=((Dimmed)?0:Configuration.LampboardBright);
    5746:	80 91 1f 01 	lds	r24, 0x011F	; 0x80011f <Dimmed.3762>
    574a:	81 11       	cpse	r24, r1
    574c:	03 c0       	rjmp	.+6      	; 0x5754 <__vector_16+0x2d2>
    574e:	80 91 c5 01 	lds	r24, 0x01C5	; 0x8001c5 <Configuration>
    5752:	01 c0       	rjmp	.+2      	; 0x5756 <__vector_16+0x2d4>
    5754:	80 e0       	ldi	r24, 0x00	; 0
    5756:	80 93 21 01 	sts	0x0121, r24	; 0x800121 <ThisBright.3757>
              Row++;
    575a:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    575e:	8f 5f       	subi	r24, 0xFF	; 255
    5760:	80 93 20 01 	sts	0x0120, r24	; 0x800120 <Row.3755>

              AInput.row5=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 3;
    5764:	89 b1       	in	r24, 0x09	; 9
    5766:	90 e0       	ldi	r25, 0x00	; 0
    5768:	80 95       	com	r24
    576a:	90 95       	com	r25
    576c:	88 7f       	andi	r24, 0xF8	; 248
    576e:	99 27       	eor	r25, r25
    5770:	23 e0       	ldi	r18, 0x03	; 3
    5772:	95 95       	asr	r25
    5774:	87 95       	ror	r24
    5776:	2a 95       	dec	r18
    5778:	e1 f7       	brne	.-8      	; 0x5772 <__vector_16+0x2f0>
    577a:	8f 71       	andi	r24, 0x1F	; 31
    577c:	98 2f       	mov	r25, r24
    577e:	99 0f       	add	r25, r25
    5780:	99 0f       	add	r25, r25
    5782:	80 91 1e 01 	lds	r24, 0x011E	; 0x80011e <AInput.3782+0x3>
    5786:	83 78       	andi	r24, 0x83	; 131
    5788:	89 2b       	or	r24, r25
    578a:	80 93 1e 01 	sts	0x011E, r24	; 0x80011e <AInput.3782+0x3>
              //((uint8_t*)&AInput)[3]|=(~PIN(LBKBSHARED_PORT) & (_BV(LBKBSHARED_COL4_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL0_PIN))) >> 2;
              DDR(KEYBOARD_PORT)&=~_BV(KEYBOARD_ROW5_PIN);
    578e:	0d 98       	cbi	0x01, 5	; 1
              if (~PIN(KEYBOARD_SEL_PORT) & _BV(KEYBOARD_SEL_PIN))
    5790:	4a 99       	sbic	0x09, 2	; 9
    5792:	03 c0       	rjmp	.+6      	; 0x579a <__vector_16+0x318>
                AInput.row6=_BV(0);
    5794:	80 68       	ori	r24, 0x80	; 128
    5796:	80 93 1e 01 	sts	0x011E, r24	; 0x80011e <AInput.3782+0x3>
                //((uint8_t*)&AInput)[3]|=_BV(0);
              break;
            }

        //columns output
        DDR(LBKBSHARED_PORT)|=_BV(LBKBSHARED_COL0_PIN) | _BV(LBKBSHARED_COL1_PIN) | _BV(LBKBSHARED_COL2_PIN) | _BV(LBKBSHARED_COL3_PIN) | _BV(LBKBSHARED_COL4_PIN);
    579a:	8a b1       	in	r24, 0x0a	; 10
    579c:	88 6f       	ori	r24, 0xF8	; 248
    579e:	8a b9       	out	0x0a, r24	; 10
        
        /*BrightTimer=0;
        ThisBright=((Dimmed)?0:Configuration.LampboardBright);
        Row++;*/

        if (Row==6)
    57a0:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    57a4:	86 30       	cpi	r24, 0x06	; 6
    57a6:	09 f0       	breq	.+2      	; 0x57aa <__vector_16+0x328>
    57a8:	86 c0       	rjmp	.+268    	; 0x58b6 <__vector_16+0x434>
          {
            Row=0;
    57aa:	10 92 20 01 	sts	0x0120, r1	; 0x800120 <Row.3755>

            //debounce
            if (InputLast==*(uint32_t*)&AInput)
    57ae:	80 91 1b 01 	lds	r24, 0x011B	; 0x80011b <AInput.3782>
    57b2:	90 91 1c 01 	lds	r25, 0x011C	; 0x80011c <AInput.3782+0x1>
    57b6:	a0 91 1d 01 	lds	r26, 0x011D	; 0x80011d <AInput.3782+0x2>
    57ba:	b0 91 1e 01 	lds	r27, 0x011E	; 0x80011e <AInput.3782+0x3>
    57be:	40 91 17 01 	lds	r20, 0x0117	; 0x800117 <InputLast.3769>
    57c2:	50 91 18 01 	lds	r21, 0x0118	; 0x800118 <InputLast.3769+0x1>
    57c6:	60 91 19 01 	lds	r22, 0x0119	; 0x800119 <InputLast.3769+0x2>
    57ca:	70 91 1a 01 	lds	r23, 0x011A	; 0x80011a <InputLast.3769+0x3>
    57ce:	48 17       	cp	r20, r24
    57d0:	59 07       	cpc	r21, r25
    57d2:	6a 07       	cpc	r22, r26
    57d4:	7b 07       	cpc	r23, r27
    57d6:	21 f4       	brne	.+8      	; 0x57e0 <__vector_16+0x35e>
              InputDebounceCount++;
    57d8:	20 91 16 01 	lds	r18, 0x0116	; 0x800116 <InputDebounceCount.3758>
    57dc:	2f 5f       	subi	r18, 0xFF	; 255
    57de:	09 c0       	rjmp	.+18     	; 0x57f2 <__vector_16+0x370>
            else
              {
                InputLast=*(uint32_t*)&AInput;
    57e0:	80 93 17 01 	sts	0x0117, r24	; 0x800117 <InputLast.3769>
    57e4:	90 93 18 01 	sts	0x0118, r25	; 0x800118 <InputLast.3769+0x1>
    57e8:	a0 93 19 01 	sts	0x0119, r26	; 0x800119 <InputLast.3769+0x2>
    57ec:	b0 93 1a 01 	sts	0x011A, r27	; 0x80011a <InputLast.3769+0x3>
                InputDebounceCount=1;
    57f0:	21 e0       	ldi	r18, 0x01	; 1
    57f2:	20 93 16 01 	sts	0x0116, r18	; 0x800116 <InputDebounceCount.3758>
              }

            //process into buffer
            if (InputState!=*(uint32_t*)&AInput && InputDebounceCount>=3)
    57f6:	40 91 ba 01 	lds	r20, 0x01BA	; 0x8001ba <InputState>
    57fa:	50 91 bb 01 	lds	r21, 0x01BB	; 0x8001bb <InputState+0x1>
    57fe:	60 91 bc 01 	lds	r22, 0x01BC	; 0x8001bc <InputState+0x2>
    5802:	70 91 bd 01 	lds	r23, 0x01BD	; 0x8001bd <InputState+0x3>
    5806:	48 17       	cp	r20, r24
    5808:	59 07       	cpc	r21, r25
    580a:	6a 07       	cpc	r22, r26
    580c:	7b 07       	cpc	r23, r27
    580e:	a1 f1       	breq	.+104    	; 0x5878 <__vector_16+0x3f6>
    5810:	20 91 16 01 	lds	r18, 0x0116	; 0x800116 <InputDebounceCount.3758>
    5814:	23 30       	cpi	r18, 0x03	; 3
    5816:	80 f1       	brcs	.+96     	; 0x5878 <__vector_16+0x3f6>
              {
                //reset inactivity
                InactivityMilliseconds=0;
    5818:	10 92 15 01 	sts	0x0115, r1	; 0x800115 <InactivityMilliseconds.3766+0x1>
    581c:	10 92 14 01 	sts	0x0114, r1	; 0x800114 <InactivityMilliseconds.3766>
                InactivityMinutes=0;
    5820:	10 92 13 01 	sts	0x0113, r1	; 0x800113 <InactivityMinutes.3767+0x1>
    5824:	10 92 12 01 	sts	0x0112, r1	; 0x800112 <InactivityMinutes.3767>

                if (InputEventCount<KEYBOARD_BUFFER_SIZE)
    5828:	20 91 be 01 	lds	r18, 0x01BE	; 0x8001be <InputEventCount>
    582c:	20 32       	cpi	r18, 0x20	; 32
    582e:	e0 f4       	brcc	.+56     	; 0x5868 <__vector_16+0x3e6>
                  {
                    InputBuffer[InputBufferIn]=*(uint32_t*)&AInput;
    5830:	e0 91 71 03 	lds	r30, 0x0371	; 0x800371 <InputBufferIn>
    5834:	34 e0       	ldi	r19, 0x04	; 4
    5836:	e3 9f       	mul	r30, r19
    5838:	f0 01       	movw	r30, r0
    583a:	11 24       	eor	r1, r1
    583c:	e2 5d       	subi	r30, 0xD2	; 210
    583e:	fe 4f       	sbci	r31, 0xFE	; 254
    5840:	80 83       	st	Z, r24
    5842:	91 83       	std	Z+1, r25	; 0x01
    5844:	a2 83       	std	Z+2, r26	; 0x02
    5846:	b3 83       	std	Z+3, r27	; 0x03
                    InputBufferIn++;
    5848:	20 91 71 03 	lds	r18, 0x0371	; 0x800371 <InputBufferIn>
    584c:	2f 5f       	subi	r18, 0xFF	; 255
    584e:	20 93 71 03 	sts	0x0371, r18	; 0x800371 <InputBufferIn>
                    if (InputBufferIn==KEYBOARD_BUFFER_SIZE)
    5852:	20 91 71 03 	lds	r18, 0x0371	; 0x800371 <InputBufferIn>
    5856:	20 32       	cpi	r18, 0x20	; 32
    5858:	11 f4       	brne	.+4      	; 0x585e <__vector_16+0x3dc>
                      InputBufferIn=0;
    585a:	10 92 71 03 	sts	0x0371, r1	; 0x800371 <InputBufferIn>
                    InputEventCount++;
    585e:	20 91 be 01 	lds	r18, 0x01BE	; 0x8001be <InputEventCount>
    5862:	2f 5f       	subi	r18, 0xFF	; 255
    5864:	20 93 be 01 	sts	0x01BE, r18	; 0x8001be <InputEventCount>
                  }

                //update inputstate
                InputState=*(uint32_t*)&AInput;
    5868:	80 93 ba 01 	sts	0x01BA, r24	; 0x8001ba <InputState>
    586c:	90 93 bb 01 	sts	0x01BB, r25	; 0x8001bb <InputState+0x1>
    5870:	a0 93 bc 01 	sts	0x01BC, r26	; 0x8001bc <InputState+0x2>
    5874:	b0 93 bd 01 	sts	0x01BD, r27	; 0x8001bd <InputState+0x3>
              }

            //inactivity
            InactivityMilliseconds++;
    5878:	80 91 14 01 	lds	r24, 0x0114	; 0x800114 <InactivityMilliseconds.3766>
    587c:	90 91 15 01 	lds	r25, 0x0115	; 0x800115 <InactivityMilliseconds.3766+0x1>
    5880:	01 96       	adiw	r24, 0x01	; 1
            if (InactivityMilliseconds==6250) //5000/6/8 * 60
    5882:	8a 36       	cpi	r24, 0x6A	; 106
    5884:	e8 e1       	ldi	r30, 0x18	; 24
    5886:	9e 07       	cpc	r25, r30
    5888:	29 f0       	breq	.+10     	; 0x5894 <__vector_16+0x412>
                //update inputstate
                InputState=*(uint32_t*)&AInput;
              }

            //inactivity
            InactivityMilliseconds++;
    588a:	90 93 15 01 	sts	0x0115, r25	; 0x800115 <InactivityMilliseconds.3766+0x1>
    588e:	80 93 14 01 	sts	0x0114, r24	; 0x800114 <InactivityMilliseconds.3766>
    5892:	11 c0       	rjmp	.+34     	; 0x58b6 <__vector_16+0x434>
            if (InactivityMilliseconds==6250) //5000/6/8 * 60
              {
                InactivityMilliseconds=0;
    5894:	10 92 15 01 	sts	0x0115, r1	; 0x800115 <InactivityMilliseconds.3766+0x1>
    5898:	10 92 14 01 	sts	0x0114, r1	; 0x800114 <InactivityMilliseconds.3766>
                if (InactivityMinutes<65535)
    589c:	80 91 12 01 	lds	r24, 0x0112	; 0x800112 <InactivityMinutes.3767>
    58a0:	90 91 13 01 	lds	r25, 0x0113	; 0x800113 <InactivityMinutes.3767+0x1>
    58a4:	8f 3f       	cpi	r24, 0xFF	; 255
    58a6:	ff ef       	ldi	r31, 0xFF	; 255
    58a8:	9f 07       	cpc	r25, r31
    58aa:	29 f0       	breq	.+10     	; 0x58b6 <__vector_16+0x434>
                  InactivityMinutes++;
    58ac:	01 96       	adiw	r24, 0x01	; 1
    58ae:	90 93 13 01 	sts	0x0113, r25	; 0x800113 <InactivityMinutes.3767+0x1>
    58b2:	80 93 12 01 	sts	0x0112, r24	; 0x800112 <InactivityMinutes.3767>
              }
          }

        if (~Lampboard[Row] & _BV(0))
    58b6:	e0 91 20 01 	lds	r30, 0x0120	; 0x800120 <Row.3755>
    58ba:	f0 e0       	ldi	r31, 0x00	; 0
    58bc:	e1 54       	subi	r30, 0x41	; 65
    58be:	fe 4f       	sbci	r31, 0xFE	; 254
    58c0:	80 81       	ld	r24, Z
    58c2:	80 ff       	sbrs	r24, 0
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL0_PIN);
    58c4:	5b 98       	cbi	0x0b, 3	; 11
        if (~Lampboard[Row] & _BV(1))
    58c6:	e0 91 20 01 	lds	r30, 0x0120	; 0x800120 <Row.3755>
    58ca:	f0 e0       	ldi	r31, 0x00	; 0
    58cc:	e1 54       	subi	r30, 0x41	; 65
    58ce:	fe 4f       	sbci	r31, 0xFE	; 254
    58d0:	80 81       	ld	r24, Z
    58d2:	81 ff       	sbrs	r24, 1
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL1_PIN);
    58d4:	5c 98       	cbi	0x0b, 4	; 11
        if (~Lampboard[Row] & _BV(2))
    58d6:	e0 91 20 01 	lds	r30, 0x0120	; 0x800120 <Row.3755>
    58da:	f0 e0       	ldi	r31, 0x00	; 0
    58dc:	e1 54       	subi	r30, 0x41	; 65
    58de:	fe 4f       	sbci	r31, 0xFE	; 254
    58e0:	80 81       	ld	r24, Z
    58e2:	82 ff       	sbrs	r24, 2
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL2_PIN);
    58e4:	5d 98       	cbi	0x0b, 5	; 11
        if (~Lampboard[Row] & _BV(3))
    58e6:	e0 91 20 01 	lds	r30, 0x0120	; 0x800120 <Row.3755>
    58ea:	f0 e0       	ldi	r31, 0x00	; 0
    58ec:	e1 54       	subi	r30, 0x41	; 65
    58ee:	fe 4f       	sbci	r31, 0xFE	; 254
    58f0:	80 81       	ld	r24, Z
    58f2:	83 ff       	sbrs	r24, 3
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL3_PIN);
    58f4:	5e 98       	cbi	0x0b, 6	; 11
        if (~Lampboard[Row] & _BV(4))
    58f6:	e0 91 20 01 	lds	r30, 0x0120	; 0x800120 <Row.3755>
    58fa:	f0 e0       	ldi	r31, 0x00	; 0
    58fc:	e1 54       	subi	r30, 0x41	; 65
    58fe:	fe 4f       	sbci	r31, 0xFE	; 254
    5900:	80 81       	ld	r24, Z
    5902:	84 ff       	sbrs	r24, 4
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL4_PIN);
    5904:	5f 98       	cbi	0x0b, 7	; 11

        switch(Row)
    5906:	80 91 20 01 	lds	r24, 0x0120	; 0x800120 <Row.3755>
    590a:	82 30       	cpi	r24, 0x02	; 2
    590c:	81 f0       	breq	.+32     	; 0x592e <__vector_16+0x4ac>
    590e:	30 f4       	brcc	.+12     	; 0x591c <__vector_16+0x49a>
    5910:	88 23       	and	r24, r24
    5912:	59 f0       	breq	.+22     	; 0x592a <__vector_16+0x4a8>
    5914:	81 30       	cpi	r24, 0x01	; 1
    5916:	81 f4       	brne	.+32     	; 0x5938 <__vector_16+0x4b6>
          {
            case 0 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW0_PIN); break;
            case 1 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW1_PIN); break;
    5918:	3b 9a       	sbi	0x07, 3	; 7
    591a:	0e c0       	rjmp	.+28     	; 0x5938 <__vector_16+0x4b6>
        if (~Lampboard[Row] & _BV(3))
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL3_PIN);
        if (~Lampboard[Row] & _BV(4))
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL4_PIN);

        switch(Row)
    591c:	84 30       	cpi	r24, 0x04	; 4
    591e:	59 f0       	breq	.+22     	; 0x5936 <__vector_16+0x4b4>
    5920:	40 f0       	brcs	.+16     	; 0x5932 <__vector_16+0x4b0>
    5922:	85 30       	cpi	r24, 0x05	; 5
    5924:	49 f4       	brne	.+18     	; 0x5938 <__vector_16+0x4b6>
            case 0 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW0_PIN); break;
            case 1 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW1_PIN); break;
            case 2 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW2_PIN); break;
            case 3 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW3_PIN); break;
            case 4 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW4_PIN); break;
            case 5 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW5_PIN); break;
    5926:	3f 9a       	sbi	0x07, 7	; 7
    5928:	07 c0       	rjmp	.+14     	; 0x5938 <__vector_16+0x4b6>
        if (~Lampboard[Row] & _BV(4))
          LBKBSHARED_PORT&=~_BV(LBKBSHARED_COL4_PIN);

        switch(Row)
          {
            case 0 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW0_PIN); break;
    592a:	3a 9a       	sbi	0x07, 2	; 7
    592c:	05 c0       	rjmp	.+10     	; 0x5938 <__vector_16+0x4b6>
            case 1 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW1_PIN); break;
            case 2 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW2_PIN); break;
    592e:	3c 9a       	sbi	0x07, 4	; 7
    5930:	03 c0       	rjmp	.+6      	; 0x5938 <__vector_16+0x4b6>
            case 3 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW3_PIN); break;
    5932:	3d 9a       	sbi	0x07, 5	; 7
    5934:	01 c0       	rjmp	.+2      	; 0x5938 <__vector_16+0x4b6>
            case 4 : DDR(LAMPBOARD_PORT)|=_BV(LAMPBOARD_ROW4_PIN); break;
    5936:	3e 9a       	sbi	0x07, 6	; 7
      }

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alank2 wrote:

Can you do a function within a function for something like this?

 

Actually, GCC allows/supports this but you'll lose portability as most/all other compilers don't.

Letting the smoke out since 1978

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess I'm reviving an old thread - I was rereading this and thinking more about it.  I like the schematic posted in #16, but having had a project with this once, I had a LED that allowed enough reverse leakage to activate a switch that was not pressed.  It also requires diodes (though it takes less pins!).  I was trying to think through what is the easiest to program for and I came up with this.  I'm sure many others have used it before.  I'm sharing the rows between a led matrix and it could be a switch matrix with more columns, but in this example the switches only have one column so they can't really be called a matrix.  The inactive rows are always HiZ and the active row is output ground.  The LED columns are always output, either low or high or off or on.  The switch columns are always input with pullup and can be sampled to see if a button is pressed when that row is active.  This should make for very simple programming:

 

repeat{

sample switch columns

disable active row

update led columns

activate next row

}

 

Sometimes I don't just want a simple monochrome LED matrix, so I have a faster ISR speed.  The way I did this previously was to say apply 8 time slots/ISR executions to each row and I would turn off a column if it was only lit say 3/8 times, etc.  That worked fine, but might not make sampling the inputs as quickly as I want at the same time.  I think it can also be improved on with this technique:

 

Still have the sped up ISR, but each time we change the active row as if it were monochrome.  This would allow us to sample the input switches much faster and feed them into debounce code.  Now though to do brightness, we keep a variable called state.  Each LED could have its own brightness or you could assign a single brightness to the entire matrix if you only needed that.  Let's say the number of brightness levels was 8.  Then if the brightness of a LED was set to a 4, each time we would add 4 to the state.  When the state is >=levels, it is on for the ISR execution and we subtract levels from it, if it is less than, then it is off for that execution.  A brightness of 4 out of 8 levels would then yield the pattern on/off/on/off/on/off.  The lowest brightness 1 would yield on/off/off/off/off/off/off/off.  Obviously a framerate must be selected that the lowest brightness is still a decent refresh rate that won't blink.  I know there is a name of this technique of adding a value, checking to see if it is above a certain value to determine on/off, but I can't recall the name (please tell me if you know it!).  Hopefully this all makes sense.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Note that a previous comment in this thread about C and "functions within functions" triggered a side-track discussion about that concept. In order that Alan has some hope of getting replies to the point he recently made in #55 that discussion now lives at: https://www.avrfreaks.net/forum/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Clawson!

Pages