Heres my code:
I seperated horizontal delay into 2 sections because revolutionTime_S ranges from about 0.032 to 2, and I dont think float would like to deal with numbers like 2,000,000? Anyway, I get no output on the ports at all. When I return a constant of say 350, the ports light up nicely. The value the function should be outputting ranges from about 350 to about 7500. All within the range of a 16 bit number. Can anyone shed light onto what's happening here?Code:#include <htc.h> #include <stdint.h> #define _XTAL_FREQ 8000000 __CONFIG (FOSC_XT & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & LVP_OFF & DEBUG_OFF); void initDigitalOut() { PORTA = PORTB = PORTC = PORTD = 0; TRISA = TRISB = TRISC = TRISD = 0; ANSEL = ANSELH = 0; } unsigned int math() { float revolutionTime_S = 3000/31250; float horizontalDelay_US = revolutionTime_S/276; float horizontalDelay_US = horizontalDelay_US*1000000; return (unsigned int) horizontalDelay_US; } void main() { initDigitalOut(); while(1) { PORTB = math(); PORTD = math() >> 8; } }
Thanks!!!



LinkBack URL
About LinkBacks


