/////////////////////////////////////////////////////////////////////////////// // bar_graph_skel.c // Tests functionality of the bar_graph display /////////////////////////////////////////////////////////////////////////////// //PORT D connections // PORT D: 7 6 5 4 3 2 1 0 // SCK (SCK)--| | | | | | | |--unused // MISO (MISO)----| | | | | |-----unused // MOSI (MOSI)-------| | | |--------unused // (unused) SS_n----------| |-----------unused // *SS_n is unused but must be configred as an output in master mode //PORT (E) connections // PORT E: 7 6 5 4 3 2 1 0 // not present--| | | | | | | |--RCLK // not present-----| | | | | |-----unused // not present--------| | |--------unused // not present-----------| |-----------unused //PORT (C) connections // PORT C: 7 6 5 4 3 2 1 0 // not present--| | | | | | | |--OE_n (PWM dimming) // not present-----| | | | | |-----unused // not present--------| | |--------unused // not present-----------| |-----------unused #include #include /////////////////////////////////////////////////////////////////////////////// // Initalize Port D SPI // void init_SPID(void){ //SPI enabled, master mode, data mode0, MSB 1st, clk/4 PORTD.DIRSET |= ???????; //configure SPI pins on port D SPID.CTRL |= ???????; //setup SPI SPID.INTCTRL = 0x00; //no interrupts } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// void init_32Mhz_RC_clk(void){ //setup 32Mhz internal RC clock OSC.CTRL = OSC_RC32MEN_bm; //enable 32MHz clock while (!(OSC.STATUS & OSC_RC32MRDY_bm)); //wait for clock to be ready CCP = CCP_IOREG_gc; //enable protected register change CLK.CTRL = CLK_SCLKSEL_RC32M_gc; //switch to 32MHz clock } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// //setup TC0 for single slope PWM void init_TC0_PWM(void){ TCC0_CTRLA |= TC_CLKSEL_DIV8_gc; //sysclock div 8 TCC0_CTRLB |= TC_WGMODE_SINGLESLOPE_gc | TC0_CCAEN_bm; //single slope, pin on TCC0_CCA = 0xD0; //compare level set (bigger values=dimmer) TCC0_PER = 0x00f0; //period set PORTC.DIRSET |= PIN0_bm; //PC.0 is the PWM output. (OC0A) } /////////////////////////////////////////////////////////////////////////////// int main(void){ uint8_t spi_data_out = ??????????; //initalize output data init_32Mhz_RC_clk(); //set clock to 32Mhz init_TC0_PWM(); //single slope PWM for dimming init_SPID(); //setup SPI on PORT D PORTE.DIRSET |= ????????????; //RCLK pin as output PORTE.OUT &= ????????????; //RCLK pin starts logic low while(1){ ????????????????????????; //send data to SPI port ????????????????????????; //wait for SPI completion ????????????????????; //toggle RCLK high ????????????????????; //RCLK goes back low ????????????????????; //shift bits ????????????????????; //check for wrap around _delay_ms(250); //make display visible };//while }//main