Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 16000000UL
- // the number of cycles it does after one loop is 10
- #define CYCLES 10
- // 1 tick at 16mhz = 0,0000000625. 1/f_cpu.
- // RESOLUTION = F_CPU / CYCLES / 16777215 24bit
- #define RESOLUTION 0.095367431640625
- volatile uint8_t runstate; // indicate on/off
- volatile uint8_t signal; // signal type
- volatile double frequency; //frequency value
- volatile uint32_t acc;
- const uint8_t sinewave[] PROGMEM = { 0x80,0x83,0x86,... }
- const uint8_t *SIGNALS[] = { sinewave, .... };
- inline void static signalOutOLD(const uint8_t *signal, uint8_t ad2, uint8_t ad1, uint8_t ad0)
- {
- asm volatile(
- "eor r18, r18 ;r18<-0"
- "eor r19, r19 ;r19<-0"
- "1:"
- "add r18, %0 ;1 cycle, (ad0) variable to r18"
- "adc r19, %1 ;1 cycle, (ad1) variable to r19"
- "adc %A3, %2 ;1 cycle, (ad2) variable to r30"
- "lpm ;3 cycles, load byte to r0 from Z pointed"
- "out %4, r0 ;1 cycle, Output data value on r0 to PortD"
- "sbis %5, 2 ;1 cycle if PB2 is set skip the jump."
- "rjmp 1b ;2 cycles, jump to 1: in unix style. 10 cycles tot"
- :
- :"r" (ad0),"r" (ad1),"r" (ad2),"e" (signal),"I" (_SFR_IO_ADDR(PORTD)), "I" (_SFR_IO_ADDR(PORTB))
- :"r18", "r19"
- );
- }
- // function is called from ISR(SPI_STC_vect) when the start|stop command is received.
- void set_runstate(void) {
- // toggle the state.
- runstate = !runstate;
- BITS_FLIP(PORTB, PB2);
- }
- int main(void) {
- // test led light1,
- BITS_SET(DDRB, PB1);
- BITS_CLEAR(PORTB, PB1);
- // asm stop bit. a led is connected to this port to indicate when the bit is set.
- BITS_SET(DDRB, PB2);
- BITS_SET(PORTB, PB2);
- runstate = 0;
- signal = 0; // signal type
- frequency = 1000; //frequency value
- acc = frequency / RESOLUTION ;
- while(1)
- {
- while(runstate == 1)
- {
- signalOutOLD(SIGNALS[signal], (uint8_t)(acc >> 16), (uint8_t)(acc >> 8), (uint8_t)acc);
- }
- _delay_ms(100);
- BITS_FLIP(PORTB, PB1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement