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.

Programming PIC16F877 using cc5x compiler

Status
Not open for further replies.

Hellsyn

New Member
hi there

I am currently programming PIC16F877 in assembly language and I managed to run the serial data tranmission (asynchronous) for the interfaced Q-TERM (LCD + keypad). The problem is, I still need to know how to access the MCU's memory to store some data coming from the QTERM. A lot told me that writing this whole program in C and using the cc5x compiler would be much easier.

My code in serial data transmission is in assembly language. I need to convert my program(assembly language) to C language (cc5x compiler) and study how to code accessing memory in C. I know C programming but i don't know how to code the serial transmission + memory allocation in cc5x. This may sound simple but I don't have enough time to just study the cc5x manual and code from there. I guess it would be a lot faster if I have some sample codes with me and maybe pattern my program to the codes.

If anyone could give/show me some codes in cc5x format, ANY code related to cc5x and PIC16F877, please..I would really appreciate it.

Thanks and more power to this forum. :D
 
Hellsyn said:
hi there

I am currently programming PIC16F877 in assembly language and I managed to run the serial data tranmission (asynchronous) for the interfaced Q-TERM (LCD + keypad). The problem is, I still need to know how to access the MCU's memory to store some data coming from the QTERM. A lot told me that writing this whole program in C and using the cc5x compiler would be much easier.

My code in serial data transmission is in assembly language. I need to convert my program(assembly language) to C language (cc5x compiler) and study how to code accessing memory in C. I know C programming but i don't know how to code the serial transmission + memory allocation in cc5x. This may sound simple but I don't have enough time to just study the cc5x manual and code from there. I guess it would be a lot faster if I have some sample codes with me and maybe pattern my program to the codes.

If anyone could give/show me some codes in cc5x format, ANY code related to cc5x and PIC16F877, please..I would really appreciate it.

If you've already written most of your project in assembler, why would you want to change to C? - it seems a completely bizarre thing to want to do?.

Presumably you are aware that the only' RAM' in a PIC is the GPR's (General Purpose Register's) - you can access a section of them easily using indexing - lookup FSR and INDF in the datasheet. It should be far easier than converting your entire program to C.
 
Hey Nigel Goodwin

Thanks for the reply.

I am to convert my code to C because there are a lot of features to be added on the MCU.

My project is similar to a liquid vending machine. Except that it takes time for the user input to be processed(assume it will take a fairly long time for the data to be processed). A user inputs some data(amount of liquid and the type of liquid) on the MCU, and then the data is transmitted to another MCU for data processing. The use of 2 MCUs implemented to support queuing. While the data is being processed by the 2nd MCU, the first MCU's task is to accept the next user's request (order).

I am planning to user GPRs of the PIC16F877 but I would still like to know how to code everything in C and continue from there. In the long run, I think it would be faster and the code would be more organized.

Thanks once again..
 
Hellsyn said:
Hey Nigel Goodwin

Thanks for the reply.

I am to convert my code to C because there are a lot of features to be added on the MCU.

My project is similar to a liquid vending machine. Except that it takes time for the user input to be processed(assume it will take a fairly long time for the data to be processed). A user inputs some data(amount of liquid and the type of liquid) on the MCU, and then the data is transmitted to another MCU for data processing. The use of 2 MCUs implemented to support queuing. While the data is being processed by the 2nd MCU, the first MCU's task is to accept the next user's request (order).

I am planning to user GPRs of the PIC16F877 but I would still like to know how to code everything in C and continue from there. In the long run, I think it would be faster and the code would be more organized.

It doesn't sound like you need two PIC's, one should be plenty.

Can't help you on C though, never use it - the vast majority of PIC programming is done using assembler, and almost all the masses of code on the Internet are in assembler.
 
cc5x

//Hello here is some code in C to do a serial read and write on the
// PIC16F877A.
#pragma chip PIC16F877A
// setup all registeres at start up.
static void setup()
{

CMCON = 0b0000.0111; // Comparator off
CCP1CON = 0b0000.0000; // Capt/Comp/PWM off

OPTION = 0b0000.0010; // WDT prescaler
//T1CON = 0b0000.0001; // Timer1 enabled, presc 1:1
INTCON = 0; // all interrupt bits off
PIR1 = 0; // ..
INTEDG = 0; // int at falling edge RB0
// (= rising of RTS!)
PIE1 = 0; // disable all ext. interrupts
PIE2 = 0; // ????????????????
PIR2 = 0; // ????????????????

PORTA = 0b.0000.0000;
TRISA = 0b.1111.1111; /* 1 = input, 0 = output*/

PORTB = 0b.1111.1111;
TRISB = 0b.0001.1000; // volt out.

PORTC = 0b.0111.1111;
TRISC = 0b.1011.1000; // RC7 = Resive, RC6 = Transmit : 16f877

PORTD = 0b.1111.1111;
TRISD = 0b.1111.1111; // volt ind instrument number.

// Set baud rate, (look up baud rate's for SPBRG in pdf file for the PIC).
SPBRG = 0x19;
TXSTA = 0b.0010.0100;
RCSTA = 0b.1001.0000;
// clean input register before read.
W = RCREG;
W = RCREG;
W = RCREG;
}

void main()
{
char Value;
setup();
if(RCIF == 1) // if data in register get it?.
{
Value = RCREG;
}
TXREG = 'A'; // Send a char
while(TRMT != 1); // wait for it to be send.
}
// Hope this is what you need?.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top