Definition in file t2313_softpwm.c.
#include <ctype.h>
#include "t2313_softpwm.h"
Include dependency graph for t2313_softpwm.c:
Go to the source code of this file.
Functions | |
void | Init (void) |
prototypes | |
__C_task | main (void) |
The program entry point. Initialises harware, and sets baudrate to 38,400 bps for a 7.3728MHz crystal. Enters an eternal loop. | |
void | ManualControl (void) |
Example of PWM control via the serial port. Waits for a synchronization character and acts upon it. | |
Variables | |
unsigned char | compare [CHMAX] |
global buffers | |
volatile unsigned char | compbuff [CHMAX] |
|
prototypes
Definition at line 184 of file t2313_softpwm.c. References CHMAX, compare, compbuff, DEBUGSET, PORTB_MASK, PORTD_MASK, and PWMDEFAULT. Referenced by main(). 00185 { 00186 unsigned char i, pwm; 00187 00188 CLKPR = (1 << CLKPCE); // enable clock prescaler update 00189 CLKPR = 0; // set clock to maximum (= crystal) 00190 00191 __watchdog_reset(); // reset watchdog timer 00192 MCUSR &= ~(1 << WDRF); // clear the watchdog reset flag 00193 WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence 00194 WDTCSR = 0x00; // disable watchdog timer 00195 00196 DDRD = PORTD_MASK; // set port pins to output 00197 DDRB = PORTB_MASK; // set port pins to output 00198 00199 #if DEBUG 00200 DEBUGSET; // make debug pin output (header file macro) 00201 pwm = 0; // worst-case default PWM level 00202 #else 00203 pwm = PWMDEFAULT; 00204 #endif 00205 00206 for(i=0 ; i<CHMAX ; i++) // initialise all channels 00207 { 00208 compare[i] = pwm; // set default PWM values 00209 compbuff[i] = pwm; // set default PWM values 00210 } 00211 00212 #if DEBUG 00213 compare[0] = 0x01; // make one channel active 00214 compbuff[0] = 0x01; 00215 #endif 00216 00217 TIFR = (1 << TOV0); // clear interrupt flag 00218 TIMSK = (1 << TOIE0); // enable overflow interrupt 00219 TCCR0B = (1 << CS00); // start timer, no prescale 00220 00221 __enable_interrupt(); // enable interrupts 00222 }
|
|
The program entry point. Initialises harware, and sets baudrate to 38,400 bps for a 7.3728MHz crystal. Enters an eternal loop.
Definition at line 97 of file t2313_softpwm.c. References DebugMonitor(), Init(), ManualControl(), and USART0_Init(). 00098 { 00099 Init(); 00100 USART0_Init(11); 00101 for(;;) 00102 { 00103 #if DEBUG 00104 DebugMonitor(); 00105 #else 00106 ManualControl(); 00107 #endif 00108 } 00109 }
Here is the call graph for this function: ![]() |
|
Example of PWM control via the serial port. Waits for a synchronization character and acts upon it.
Definition at line 113 of file t2313_softpwm.c. References CHMAX, compbuff, GetNextChar(), USART0_Receive(), and USART0_Transmit(). Referenced by main(). 00114 { 00115 unsigned char rxdata, channel, temp, error; 00116 00117 error = 0; // clear error flag 00118 while(USART0_Receive() != '#'); // wait for sync character 00119 USART0_Transmit('#'); // echo sync character 00120 channel = USART0_Receive() - 0x30; // receive channel number 00121 if(channel >= CHMAX) error = 1; // error if invalid channel 00122 USART0_Transmit(channel + 0x30); // echo received character 00123 00124 temp = GetNextChar(); // fetch upper nibble 00125 USART0_Transmit(temp); // echo received character 00126 if (isxdigit(temp)) // check for a hex character 00127 { 00128 if ( temp > '9') temp -= 7; // subtract offset for A-F 00129 temp -= 0x30; // subtract ASCII offset 00130 } 00131 else error = 1; // error if not hex 00132 rxdata = temp << 4; // store received upper nibble 00133 00134 temp = GetNextChar(); // fetch lower nibble 00135 USART0_Transmit(temp); // echo received character 00136 if (isxdigit(temp)) // check for a hex character 00137 { 00138 if ( temp > '9') temp -= 7; // subtract offset for A-F 00139 temp -= 0x30; // subtract ASCII offset 00140 } 00141 else error = 1; // error if not hex 00142 rxdata += temp; // add lower nibble to upper nibble 00143 00144 if(!error) // if data is good 00145 { 00146 compbuff[channel] = rxdata; // update compare buffer 00147 00148 USART0_Transmit(':'); // send OK message 00149 USART0_Transmit('O'); 00150 USART0_Transmit('K'); 00151 USART0_Transmit('\r'); 00152 USART0_Transmit('\n'); 00153 } 00154 else // if data is not good 00155 { 00156 USART0_Transmit(':'); // send ERRor message 00157 USART0_Transmit('E'); 00158 USART0_Transmit('R'); 00159 USART0_Transmit('R'); 00160 USART0_Transmit('\r'); 00161 USART0_Transmit('\n'); 00162 } 00163 }
Here is the call graph for this function: ![]() |
|
global buffers
Definition at line 87 of file t2313_softpwm.c. Referenced by Init(). |
|
Definition at line 88 of file t2313_softpwm.c. Referenced by Init(), and ManualControl(). |