PICmicro & dsPIC >> PICmicro & dsPIC

Pages: 1
kit007
stranger


Reged: Jun 29 2009
Posts: 2
another newbie with 12f629
      #118902 - Mon Jun 29 2009 06:11 AM

Helo everybody, I have a problem to start my very first program using Hi-Tech compiler and 12f629. I've never use this combination, but I've work with 12f629 under ASM. It is first time when I try Hi-Tech.
How it look the skeleton of program? More, how it is translated sequence:
Code:
BSF	STATUS,RP0
CALL 0X3FF
MOVWF OSCCAL
BCF STATUS,RP0


I need a small template to start my work.
Many thanks.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Neil_K

***

Reged: Mar 09 2005
Posts: 961
Loc: NY,USA
Re: another newbie with 12f629 [Re: kit007]
      #118942 - Mon Jun 29 2009 11:06 AM

Here is code for the PIC12F683

Code:

void main(void)
{
static bit PulseA;
static bit PulseB;
static bit Blink;


OSCCON = 0x51; // 2 MHz
// Tmr2 to 48 Hz interupt
TMR2 = 0;
PR2 = 40;
T2CON = 0xFF; // Prescaler = 16, PostScaler = 16
TMR2IF = 1;
WDTCON = 0b00010011; // Watchdog On .5 sec
// Init Pins
GPIO = 0b00000000; // All Drives as outputs (GP0 and 1 must be 0)
TRISIO = 0b11111111; // All pins as Inputs
ANSEL = 0b00000000; // All pins Digital
GPPU = 0; // Master Enable Pullups
WPU = 0b00110100; // Set Pullups on
// start Off
PulseA = 1; // Start with Rapid Fire output Off
PulseB = 1;

while(!HTS); // wait for the Osc to stabilize


// start main loop
while(1)
{
// A Control Toggle Button
if(TMR2IF)
{
// clear flag
TMR2IF = 0;

// A Toggle output
if(INPUT_A == 0) // Button Pressed?
{
PulseA = !PulseA; // Toggle trigger
}
else // not pressed
{
PulseA = 1; // trigger up
}
OUT_A = PulseA; // set output

// B Toggle output
if(INPUT_B == 0) // Button Pressed?
{
PulseB = !PulseB; // Toggle trigger
}
else // not pressed
{
PulseB = 1; // trigger up
}
OUT_B = PulseB; // set output

// Blink LED if either buton is pressed
if(INPUT_A == 0 || INPUT_B == 0)
{
Blink = !Blink; // Blink
LED = Blink; // write it to LED
}
else
{
LED = LED_OFF;
}

CLRWDT(); //kick watchdog

} // end if

} // end while(1)

} // end Main




Post Extras: Print Post   Remind Me!   Notify Moderator  
kit007
stranger


Reged: Jun 29 2009
Posts: 2
Re: another newbie with 12f629 [Re: Neil_K]
      #118992 - Tue Jun 30 2009 02:41 AM

thank you, its a good start.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
2 registered and 61 anonymous users are browsing this forum.

Moderator:  mikerj, jtemples, jeff, Dan Henry, Andrew L 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Topic views: 380

Rate this topic

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5