Anh chị giúp e giải thích đoạn code này cái. E hok hiểu cái đoạn ctrình con "void DAC_Output(unsigned int valueDAC)".
sbit Chip_Select at RC0_bit;
sbit Chip_Select_Direction at TRISC0_bit;
unsigned int value;
void InitMain() {
TRISA0_bit = 1;
TRISA1_bit = 1;
Chip_Select = 1;
Chip_Select_Direction = 0;
SPI1_Init();
}
void DAC_Output(unsigned int valueDAC) {
char temp;
Chip_Select = 0;
temp = (valueDAC >> 8) & 0x0F;
temp |= 0x30;
SPI1_Write(temp);
temp = valueDAC;
SPI1_Write(temp);
Chip_Select = 1;
}
void main()
{
ANSEL = 0;
ANSELH = 0;
InitMain();
value = 2048;
while (1) {
if ((RA0_bit) && (value < 4095)) { // If RA0 button is pressed
value++; // increment value
}
else {
if ((RA1_bit) && (value > 0)) { // If RA1 button is pressed
value--; // decrement value
}
}
DAC_Output(value); // Send value to DAC chip
Delay_ms(1);
}}
sbit Chip_Select at RC0_bit;
sbit Chip_Select_Direction at TRISC0_bit;
unsigned int value;
void InitMain() {
TRISA0_bit = 1;
TRISA1_bit = 1;
Chip_Select = 1;
Chip_Select_Direction = 0;
SPI1_Init();
}
void DAC_Output(unsigned int valueDAC) {
char temp;
Chip_Select = 0;
temp = (valueDAC >> 8) & 0x0F;
temp |= 0x30;
SPI1_Write(temp);
temp = valueDAC;
SPI1_Write(temp);
Chip_Select = 1;
}
void main()
{
ANSEL = 0;
ANSELH = 0;
InitMain();
value = 2048;
while (1) {
if ((RA0_bit) && (value < 4095)) { // If RA0 button is pressed
value++; // increment value
}
else {
if ((RA1_bit) && (value > 0)) { // If RA1 button is pressed
value--; // decrement value
}
}
DAC_Output(value); // Send value to DAC chip
Delay_ms(1);
}}
Comment