Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iom128.h>
- #include <inavr.h>
- //Program configuration
- //#define ISR_PROCESSING
- #define PTR_ACCESS
- #define LED_SEG PORTE
- #define LED_SEG_DIR DDRE
- #define LED_DG PORTB
- #define LED_DG_DIR DDRB
- #define DV_480Hz 15
- #define DV_DEMO 40
- #define DV_NEXT 13
- #define DEC_OFF 0x3F
- #define DISP_MAX 6
- #define LED_BLANK 15
- typedef union TRQ {
- //Access to entire byte
- unsigned char c;
- struct {
- unsigned char f_tck : 1;
- //other flags can be defined
- unsigned char not_used : 7;
- };
- } TRQ;
- //Decoding table based on CD4056 -> '0123456789LHPA- '
- __flash unsigned char BCD_2_LED[] = {
- 0xDE, 0x82, 0xEC, 0xE6,
- 0xB2, 0x76, 0x7E, 0xC2,
- 0xFE, 0xF6, 0x1C, 0xBA,
- 0xF8, 0xFA, 0x20, 0x00 };
- __flash unsigned char DEC_1_OF_6[] =
- {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF};
- //Global variables
- unsigned char disp[6] = {0,0,0,0,0,0};
- unsigned char cur_disp;
- unsigned char dv_demo = DV_DEMO;
- unsigned char dv_next = DV_NEXT;
- __no_init unsigned char idx;
- #define UPDATE_DISP_RQ 0x01
- volatile TRQ rq;
- void InitDevices()
- {
- LED_DG = 0xFE;
- LED_DG_DIR = 0xFF;
- LED_SEG_DIR = 0xFF;
- //Prescaler fclk / 1024 = 7200Hz
- //Prescaler for T0 is different than for T1,T2,T3
- OCR0 = DV_480Hz - 1;
- TCCR0 = (1 << WGM01) | (1 << CS02) | (1 << CS01) | (1 << CS00);
- TIMSK = (1 << OCIE0);
- __enable_interrupt();
- }
- void DispDemo()
- {
- unsigned char i;
- if(--dv_next)
- {
- //Johnson counter
- for(i=5; i; i--)
- disp[i] = (disp[i] & 0xFE) | (disp[i-1] & 0x01);
- disp[0] = (disp[0] & 0xFE) | (~disp[5] & 0x01);
- return;
- }
- dv_next = DV_NEXT;
- //Shift display content
- for(i=5; i; i--)
- {
- disp[i] = (disp[i] & 0x01) | (disp[i-1] & 0xFE);
- }
- //New pattern generation
- if(idx & 0x10)
- {
- disp[0] = BCD_2_LED[LED_BLANK];
- }
- else
- {
- disp[0] = BCD_2_LED[idx];
- }
- //Take care for operator precedence
- if((++idx) == 0x16) idx = 0;
- }
- #pragma vector = TIMER0_COMP_vect
- __interrupt void T0_COMP_ISR()
- {
- LED_DG |= DEC_OFF;
- LED_SEG = disp[cur_disp];
- LED_DG = DEC_1_OF_6[cur_disp];
- if((++cur_disp) == DISP_MAX) cur_disp = 0;
- if(--dv_demo) return;
- dv_demo = DV_DEMO;
- #ifdef ISR_PROCESSING
- DispDemo();
- #else
- rq.f_tck = 1;
- #endif
- }
- void main()
- {
- idx = 0;
- cur_disp = 0;
- //dv_next = DV_NEXT;
- //dv_demo = DV_DEMO;
- InitDevices();
- while(1)
- {
- #ifndef ISR_PROCESSING
- if(rq.f_tck)
- {
- rq.f_tck = 0;
- DispDemo();
- }
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement