??? 11/24/09 08:36 Read: times |
#171104 - A comment on layout Responding to: ???'s previous message |
The idea behind indenting your source code is to make visually clear where one line "contains" or "controls" other lines: the "contained" or "controlled" lines are indented relative to their "containing" or "controlling" lines.
Thus, rather than void main (void) { /*----------------------------------------------- Configure the serial port -----------------------------------------------*/ SCON = 0x50; TMOD |= 0x20; TH1 = 0xFA; TR1 = 1; TI = 1; PCON |= 0x80;where the SFR settings are all at the same level as "void main (void)", I would find it clearer like this: void main (void) { /*----------------------------------------------- Configure the serial port -----------------------------------------------*/ SCON = 0x50; TMOD |= 0x20; TH1 = 0xFA; TR1 = 1; TI = 1; PCON |= 0x80;making it clear that those lines are "contained within" the main function. Similarly, the 'while' would be on the same level as those SFR settings, and the lines within the 'while' indented to the next step: void main (void) { /*----------------------------------------------- Configure the serial port -----------------------------------------------*/ SCON = 0x50; TMOD |= 0x20; TH1 = 0xFA; TR1 = 1; TI = 1; PCON |= 0x80; ADC0CON = 0x07; SF = 0x0D; while (1) { unsigned int conv_val; /*----------------------------------------------- Start a conversion and wait for it to complete. -----------------------------------------------*/ ADCMODE |= 0x22; /*Enables Primary ADC*/ while (RDY0 != 1); RDY1 = 0; /*Ready bit for PRIMARY ADC */ /*----------------------------------------------- Read A/D data and print it out. -----------------------------------------------*/ conv_val = ADC0M | ((ADC0H) << 8); printf ("Primary ADC Channel 3 = %urn", conv_val); } } Your indenting is also being messed-up by using TABs: You can never rely upon the interpretation of TABs, so it's best not to use them - any decent programmer's editor can be configured to insert Spaces when you press the TAB button on your keyboard... |
Topic | Author | Date |
Serial Port Configuration - UART - ADuC816 | 01/01/70 00:00 | |
Be specific! | 01/01/70 00:00 | |
Keil working again. | 01/01/70 00:00 | |
A comment on layout | 01/01/70 00:00 | |
PLL | 01/01/70 00:00 | |
Someone experienced with 8052 programming![]() | 01/01/70 00:00 |