Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

converting mikro c codes to mplab

Status
Not open for further replies.

clarence501

Junior Member level 3
Joined
Jan 24, 2011
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Philippines
Activity points
1,463
Sirs, Madams, I have found a progarm for 1hz clock generator and I want to test it. But it's using mikro C codes and I'm only familiar with mplab codes and I don't know how to convert this codes. Here they are:


// PIC12F675
// 1Hz Time Base Osc.
// Timer1 Module
// 32.768 KHz
unsigned short tick;
void Init ();
void interrupt ()
{
if (PIR1.TMR1IF)
{
TMR1H = 0xE0;
PIR1.TMR1IF = 0;
tick = 1;
}
}
void main ()
{
tick = 0;
//Initialize Ports and Timer1 Module
Init ();
while (1)
{
if (tick)
{
tick = 0;
GPIO = (1 << 2);
}
if (TMR1H > 0xF0)
{
GPIO = 0;
}
}
}
void Init ()
{
TRISIO = 0;
//Make all pins as output ports
GPIO = 0;
//Use Timer1 module
INTCON.GIE = 1;
INTCON.PEIE = 1;
T1CON = 0x01;
//Overflow every 8192
TMR1H = 0xE0;
TMR1L = 0x00;
// Enable TMR1 interrupt
PIE1.TMR1IE = 1;
}


I hope somebody can help me with this. Thanks in advance. I'm still a beginner with programming.

- - - Updated - - -

I hope someone can help me solve this problem. Please, just even help me with translating this codes, so that I can practice in doing it in MPLAB.
 

Try this


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// PIC12F675
// 1Hz Time Base Osc.
// Timer1 Module
// 32.768 KHz
 
unsigned short tick;
 
void Init ();
 
void interrupt ()
{
    if (PIR1bits.TMR1IF)
    {
        TMR1H = 0xE0;
        PIR1bits.TMR1IF = 0;
        tick = 1;
    }
}
 
void main ()
{
    tick = 0;
    //Initialize Ports and Timer1 Module
    Init ();
    while (1)
    {
        if (tick)
        {
            tick = 0;
            GPIO = (1 << 2);
        }
        if (TMR1H > 0xF0)
        {
            GPIO = 0;
        }
    }
}
 
void Init ()
{
    TRISIO = 0;
    //Make all pins as output ports
    GPIO = 0;
    //Use Timer1 module
    INTCONbits.GIE = 1;
    INTCONbits.PEIE = 1;
    T1CON = 0x01;
    //Overflow every 8192
    TMR1H = 0xE0;
    TMR1L = 0x00;
    // Enable TMR1 interrupt
    PIE1bits.TMR1IE = 1;
}

 

still has a lot of errors when i try to build this all in mplab sir. Where do I start with making a code for 1hz generator using mplab?

- - - Updated - - -

there seems to be no difference in the codes sir
 

Maybe you are getting errors for TRISIO and GPIO if you are using PIC16F or PIC18F. Which PIC are you using? Which Toolsuite are you using with MPLAB to Compile the Code?

Code by Lahman Marcel for Hi-Tech C Compiler.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// PIC12F675
// 1Hz Time Base Osc.
// Timer1 Module
// 32.768 KHz
#include <htc.h>
 
unsigned short tick;
void Init ();
void interrupt isr ()
{
if (PIR1bits.TMR1IF)
{
TMR1H = 0xE0;
PIR1bits.TMR1IF = 0;
tick = 1;
}
}
void main ()
{
tick = 0;
//Initialize Ports and Timer1 Module
Init ();
while (1)
{
if (tick)
{
tick = 0;
GPIO = (1 << 2);
}
if (TMR1H > 0xF0)
{
GPIO = 0;
}
}
}
void Init ()
{
TRISIO = 0;
//Make all pins as output ports
GPIO = 0;
//Use Timer1 module
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
T1CON = 0x01;
//Overflow every 8192
TMR1H = 0xE0;
TMR1L = 0x00;
// Enable TMR1 interrupt
PIE1bits.TMR1IE = 1;
}

 
Last edited:

Im using the Hi Tech C compiler. But still has a lot of errors sir.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top