DDS Function Generator Embedded C Code
DDS Function Generator Embedded C Code
DDS Function Generator Embedded C Code
// Main function
int main(void)
{
DDRC &= ~(0x38); // Set PC3, PC4, PC5 as input
AD_init(); // Initialize AD9833
lcd_init(); // Initialize LCD
_delay_ms(1000); // Delay for LCD to stabilize
int x = 0; // Mode switch variable
float freq_val = 0; // Variable to store frequency value
char str_temp[10]; // Temporary string buffer
while (1)
{
freq_val = AD_getFrequency(); // Get current frequency
if ((freq_val > 100) && (freq_val < 100000))
{
if (PINC & (1<<PC5)) // Check if PC5 is pressed
{
AD_setFrequency(freq_val + 100); // Increase frequency by 100
Hz
}
if (PINC & (1<<PC4)) // Check if PC4 is pressed
{
AD_setFrequency(freq_val - 100); // Decrease frequency by 100
Hz
}
}
return 0;
}