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.

PWM from PIC16F877a....

Status
Not open for further replies.
Can't we do anything else then buying other serial module for now!!
only for sending 8 bits adresh result to another uC??
 
It it possible to use it for 8bit data transfer only 1 or 2 meters or should i buy tht serial 2.4Ghz link???

in this way the data is to be send??
The pattern of bits " 0 1 1 1 1 0 0 1 " encodes to " 01 10 10 10 10 01 01 10".
 
Last edited:
Hi,

I have got these **broken link removed** as suggested by you for serial comm for sending adc result from uC to another ....
 
Did you download the manual!!!!!!

I did it was very easy..

rxtx.PNG
 
OK, but that code need to be some changes for Tx and Rx...

for Tx example
Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
 
void  HSerinit();
 
void main(void)                        // program entry
    {

    int index = 0;
    unsigned char ch;
    ADCON1 = 0x6;                    // Analogue off                    
    HSerinit();
       __delay_ms(150);
    while(1)                        // endless Loop
        {

        
         while(!TXIF);                    // Wait for module to finish
         TXREG = 'A';  
             
 
        }
    }
void HSerinit()
{
    TRISC = 0x80;                    // TX was an input!
    SPBRG = 129;                    // 20Mhz xtal 9600 BAUD
    TXSTA = 0x24;                    // TXEN and BRGH
    RCSTA = 0x90;                    // SPEN and CREN
}



FOR rX

Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
 
 
unsigned char  HSerin(void);
void HSerout(unsigned char ch), HSerinit(void);
 
void main(void)						// program entry
	{

	TRISB=0X00;
	PORTB=0X00;
	int index = 0;
	unsigned char ch;
	ADCON1 = 0x6;					// Analogue off					
	HSerinit();
       __delay_ms(150);
	while(1)						// endless Loop
		{
	      if(RCREG=='A'){
	RB7=1;}				//FOR TESTING RECEIVED DATA....!!
 
		}
	}
 
void HSerinit()
	{
	TRISC = 0xC0;					// should ideally be set
	SPBRG = 129;					// 20Mhz xtal 9600 BAUD
	TXSTA = 0x24;					// TXEN and BRGH
	RCSTA = 0x90;					// SPEN and CREN
	}
 
New code for Tx....

Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
 
void  HSerinit();
 
void main(void)                        
    {

TRISA = 0xff ;
ADCON1=0b00000000;
ADCON0=0b10000001;//000 = channel 0, (RA0/AN0)
	ADIF=0;
	ADIE=1;
	PEIE=1;                                   
    HSerinit();
       __delay_ms(150);
    while(1)                
        {

	__delay_ms(10);
    GO_DONE=1;
	__delay_ms(10);
        
         while(!TXIF);                 
         TXREG = ADRESH;              
 
        }
    }
void HSerinit()
{
    TRISC = 0x80;                    // TX was an input!
    SPBRG = 129;                    // 20Mhz xtal 9600 BAUD
    TXSTA = 0x24;                    // TXEN and BRGH
    RCSTA = 0x90;                    // SPEN and CREN
}




for rx ADC result to PWM


Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
 
void  HSerinit();
 
void main()                        
    {


    PR2 = 0b11111001 ;
	T2CON = 0b00000100 ;   
	CCP1CON = 0b00111100;                  
  ADCON1 = 0x6;  
 HSerinit();
 __delay_ms(150);
	while(1)
		{
     while(!RCIF);					// Wait for a character
		CCPR1L= RCREG; 

}
	}















void HSerinit()
{
    TRISC = 0x80;                    // TX was an input!
    SPBRG = 129;                    // 20Mhz xtal 9600 BAUD
    TXSTA = 0x24;                    // TXEN and BRGH
    RCSTA = 0x90;                    // SPEN and CREN
}
 
Last edited:
Ok... One thing I want to ask..... Why are you messing with the ADC interrupts

Code:
	ADIF=0;
	ADIE=1;
	PEIE=1;

You are not using interrupts so there is no need to set them
This will confuse the issue..

The code needs a Hserin and Hserout routine. You also need to encapsulate the ADC routine...

Can you just give me a brief note on what controls what... Ie... control characters... Whats sent by the PC and what the micro returns..
 
OK, i am working on Wireless dc motor speed control using 877a
so, one uC will read the ADC and send this ADC result via UART then this ADC result will be received with another uC it will generate PWM according to it.( using that 2.4Ghz module i linked you)
 
Status
Not open for further replies.

Latest threads

Back
Top