|
|
View previous topic :: View next topic |
Author |
Message |
eem2am
Joined: 18 Jul 2012 Posts: 21
|
PIC10F200: Disable pullups, Wdt, Setting ports |
Posted: Tue Jul 24, 2012 3:31 am |
|
|
Hello, i am using PIC10F200 and am wishing to:-
1...disable pullups
2...set up WDT to slowest rate
3...initially set ports to inputs (high impedance)
4....Calibrate the internal oscillator
Do you know how i do these things?.....i dont seem to be having much luck...........otherwisse my code builds fine
Code: | #include <10F200.h>
#use standard_io(B)
#use delay(clock=4M)
#fuses WDT,NOPROTECT, NOMCLR
#define PIN_TRIGGER PIN_B0 // Output high to trigger
#define PIN_SYNC PIN_B1 // Output low to send sync pulse; Input when listen for sync pulse
#define PIN_PHASE PIN_B2 // Input low flashes IN sync; Input high = anti sync;
// Low to high at 50Hz means AC input, so flash in sync.
#define PIN_FPM PIN_B3 // Input high = 75FPM; Input low = 60FPM
#define ANTI_SYNC 1
#define IN_SYNC 0
#define FPM60 1
#define FPM75 0
#define AC 0
#define DC 1
#define YES 1
#define NO 0
//Remember to disable internal pullups
//Remember to enable watchdog and add clrwdt instuctions
//Remember to calibrate the internal oscillator.
//Are they outputs or inputs by default.?...or are they high impedance by default?
//can you set a port to high Z by just reading from it?
//STATUS REGISTER, Option register,
//DECLARE GLOBAL VARIABLES
short int ACDCflag = DC; //High = DC; Low = AC
short int PHASEflag = IN_SYNC; //Low = in-sync; High = out-of-sync
short int FPMflag = FPM60; //High = 60FPM; Low = 75FPM
short int value=0;
short int value1=0;
short int SYNC_pulse_detected=NO;
int i;
int counter;
void send_trigger_pulse(void) {
output_bit(PIN_TRIGGER,1); //SEND TRIGGER PULSE
delay_us(10);
output_bit(PIN_TRIGGER,0);
}
void send_sync_pulse(void) {
output_bit(PIN_SYNC,0); //SEND SYNC PULSE
delay_ms(10);
value = input(PIN_SYNC); //SETS PIN_SYNC to High Impedance.
}
///////////////////////////////////////////////////////////////////////////////////////////
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
void flash(void){
while(1){
SYNC_pulse_detected = NO;
if (PHASEflag == IN_SYNC) {send_trigger_pulse();}
//10ms
send_sync_pulse();
for (i=0; i<3; i++) { //Dont listen for sync pulses within 30ms of the sent SYNC pulse.
delay_ms(10);
}//next i
//40ms
if (FPMflag == FPM60) {counter = 205;}
if (FPMflag == FPM75) {counter = 155;}
for (i=0; i<counter; i++) {
if (!input(PIN_SYNC)) {SYNC_pulse_detected = YES; break; }
delay_ms(2);
}//next i
if (SYNC_pulse_detected == YES) {continue;}
//350ms
//450ms
for (i=0; i<5; i++) { //STOP LISTENING FOR SYNC PULSE DUE TO CPI "SECOND" PULSE.
delay_ms(10);
}//next i
if (PHASEflag == ANTI_SYNC) {send_trigger_pulse();}
for (i=0; i<5; i++) { //STOP LISTENING FOR SYNC PULSE DUE TO CPI "SECOND" PULSE.
delay_ms(10);
}//next i
//450ms
//550ms
if (FPMflag == FPM60) {counter = 210;}
if (FPMflag == FPM75) {counter = 110;}
for (i=0; i<210; i++) {
if (!input(PIN_SYNC)) {SYNC_pulse_detected = YES; break; }
delay_ms(2);
}//next i
//770ms
//970ms
if (SYNC_pulse_detected == YES) {continue;}
for (i=0; i<3; i++) { //Dont listen for sync pulses within 30ms of the sent SYNC pulse.
delay_ms(10);
}//next i
//1000ms
}
} // end of
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///////////////////////////////////////////////////////////////////////////////////////////
//M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
// Main program starts here
void main(void)
{
//Disable port B pullups
// port_b_pullups(FALSE);
setup_counters(RTCC_INTERNAL, WDT_2304MS);
//ENSURE TIGGER OUTPUT IS LOW
output_bit(PIN_TRIGGER, 0);
for (i=0; i<10; i++) { //Start up delay
delay_ms(10);
}//next i
//SET FPM FLAG
FPMflag = input(PIN_FPM);
//SET PHASE FLAG
PHASEflag = input(PIN_PHASE);
//SEE IF AC or DC
for (i=0; i < 20; i++) {
value = input(PIN_PHASE);
delay_ms(5);
value1 = input(PIN_PHASE);
if (value != value1) {ACDCflag = AC; break; }
}//next i
//DELAY TO ENSURE TUBE CAPACITOR HAS CHARGED UP ENOUGH TO FLASH THE TUBE.
for (i=0; i<60; i++) { //Start up delay
delay_ms(10);
}//next i
flash();
} // end of main
//M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jul 24, 2012 7:49 am |
|
|
The internal oscillator is automatically calibrated. If you select the internal oscillator, the compiler adds the code to read the calibration value and load it at the start of the program. - Provided you have not done a full erase on the chip. If you have, you _will_ have lost the calibration value. Most programmers have an option to save this, and this must be enabled. If the value has been lost, some programmers have the ability to re-calculate the value needed, otherwise you will need to try 'trial and error', using a #rom statement to put values back until the timings approach the correct values....
Ports wake up as high impedance - read the data sheet.
setup_wdt(WDT_2304MS);
Key here is to read the processor include file.
port_b_pullups(FALSE);
Also, the 'clrwdt' instruction, is 'restart_wdt()'.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|