
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instructions for writing a c or assembly language subroutine named 'writetodac' to write a 12-bit integer value to dac channel a along with the appropriate command to update the dac. The required registers and their addresses, as well as a sample c program to test the subroutine.
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Function: WriteToDAC Created by: YOU Description: Called from C with a 12-bit integer value it writes this integer to DAC channel A along with the appropriate command to update the DAC.
SPICR 0x84160060 SPI Control Register SPISSR 0x84160070 SPI Slave Select Register SPIDTR 0x84160068 SPI Data Transfer Register (FIFO) SPISR 0x84160064 SPI Status Register
Program: HW 6 Created by: WTB Description: Rotary knob is used to set a voltage between 0 and 3.2V in steps of 0.1V. This voltage value is displayed on the LCD and is output to the DAC on channel A. Last Revision: 10/16/ ****************************************************************************************/ //Defines #define CMD 0 //send command to LCD #define DATA 4 //send data to LCD //Prototypes extern "C" void LCD_write (int cmd_data, char data); extern "C" int Rotary(void); extern "C" void sleep(int microseconds); void LCD_char(int index, char letter); void WriteToDAC(int output); int main(void) { int voltage=0,input,ind; LCD_write(CMD,1); //clear LCD sleep(1640); for (ind=0;ind<9;ind++) LCD_char(ind+2,"0.0 Volts"[ind]);//write initial value of voltage while (1) { if ((input=Rotary())) { //if the switch has moved voltage += input; if (voltage>32) voltage=32; //enforce voltage bounds if (voltage<0) voltage=0; ind=voltage/10; //write out new voltage to LCD LCD_char(2,'0'+ind); LCD_char(4,'0'+voltage-ind10); ind=(voltage4096)/33; //convert voltage to DAC counts WriteToDAC(ind); //send to DAC } } } void LCD_char(int index, char letter) { LCD_write(CMD,(char)(0x80|index)); LCD_write(DATA,letter); }