Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Converting CCS to XC8

Status
Not open for further replies.

Muscleman

New Member
Hello people, I'm doing a project based on this one:**broken link removed**
but then the code provided by the author is based on ccs, but i need to convert it to xc8
here is the code

Code:
#include <16f877a.h>
#include <defs_877.h>
#use     delay(clock=10000000)
#fuses   hs,nowdt,nocpd,nolvp,noprotect
#byte portb=0x06
#byte portd=0x08
#bit  clock=portd.6
#bit  data=portd.7
unsigned int8 i,j,index1,n,
addr[11]={0xEA,0xEA,0x2A,0x2A,0x2A,0x2A,0xAA,0x82,0xFF,0xFF,0xFF},
cont[11];
void main()
{
     set_tris_b(0x00);
     set_tris_d(0x00);
    while(1)
    {
        for(n=0;n<=99;n++)
       {
            data=1;
            for(i=0;i<=7;i++)
            {
                clock=1;
                portb=addr[i];
                delay_ms(1);
                clock=0;
                data=0;
            }
        }

        for(j=0;j<=10;j++)
        {
            cont[j]=addr[j];
        }
        for(j=0;j<=9;j++)
        {
            addr[j]=cont[j+1];
        }
        addr[10]=cont[0];

    }
}
here is my attempt at converting to xc8
Code:
#include <xc.h>
#include <htc.h>
#include <stdint.h>
#pragma config WDTE=OFF
#pragma config LVP=OFF
#pragma config PWRTE=OFF
#pragma config DEBUG=OFF
#pragma config FOSC=HS
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/10000000.0)))
#define   _XTAL_FREQ 10000000

int main(void)
{

uint8_t i,j,index1,n,
addr[11]={0xEA,0xEA,0x2A,0x2A,0x2A,0x2A,0xAA,0x82,0xFF,0xFF,0xFF},
cont[11];
     TRISB=0x00;
     TRISD=0x00;


    while(1)
    {
        for(n=0;n<=99;n++)
       {
          PORTDbits.RD7=1;


            for(i=0;i<=7;i++)
            {
               PORTDbits.RD6=1;

                PORTB=addr[i];
                __delay_ms(1);
                PORTDbits.RD6=0;
                PORTDbits.RD7=0;


            }
        }

        for(j=0;j<=10;j++)
        {
            cont[j]=addr[j];
        }

        for(j=0;j<=9;j++)
        {
            addr[j]=cont[j+1];
        }
        addr[10]=cont[0];

    }
}
I'm not sure how to convert
#byte portb=0x06
#byte portd=0x08
#bit clock=portd.6
#bit data=portd.7
I would appreciate some help thanks.
 
Last edited:
Just remove these.

Note that the original programs sets D6 at the beginning of the inner loop while you set D7.
 
ok thanks, about the other statement or my conversion of data=1 or 0 to PORTDbits.RD7=1 or clock=1 or 0 to PORTDbits.RD6=1 is it correct? because I uploaded to the program to my pic (actual circuit) but the dot matrix shows only blinking lights
 
Yes. The original program is setting data (D7) to 1 for the first execution of the inner loop and to 0 for the rest of them, and cycles the clock (D6) every loop. Is that what you're trying to accomplish?
 
Yes sir, I just based it on the original program of the author, other than that are there any flaws in my conversion that could not make the desired output( driving dot matrix)?
 
Aside of these lines, not present in the oringinal:

C:
PORTB=0x06;
PORTD=0x08;

which are not harmful, and the fact you set D7 instead of D6 in the inner loop, the programs look identical to me.
 
Aside of these lines, not present in the oringinal:

C:
PORTB=0x06;
PORTD=0x08;

which are not harmful, and the fact you set D7 instead of D6 in the inner loop, the programs look identical to me.
Ooops, I just noticed I set d7(data)=1 instead of d6(clock)=1 in the for i loop:facepalm: , I edited the code now to which I removed:
PORTB=0x06;
PORTD=0x08;
edit:I had included earlier that code^ because i thought I would convert this one also:
#byte portb=0x06
#byte portd=0x08
 
Last edited:
Thanks so much for help!! :) it's now working in the proteus isis simulation, all I have to do now is connect it again in the actual circuit, but tomorrow is the day I can test because someone's taken care of the pcb development today
 
Status
Not open for further replies.

Latest threads

Back
Top