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.

[SOLVED] How to clear memory in mikrocontroller

Status
Not open for further replies.

Johnny Churne

Member level 5
Member level 5
Joined
Jun 5, 2015
Messages
83
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
554
some time i startup my pic 16f876a it work without follow the instruction! I used serial port to send data to it and some time it repeat about 3 times. please help my knowledge is limited.
 

Maybe you have enabled WDT (Watch Dog Timer) but not clearing the WDT and maybe this is causing the PIC to reset and restart repeatedly and causing the Serial printing to be done more than one time or maybe stack is overflowing and causing the PIC to reset and restart.
 

I don't know exactly but this is my code:
Code:
char  receive[64] ;
void main(){
int x;
int i=0;
TRISA=0X00;
TRISB=0XFF;
TRISC=0X80;
PORTC=0X00;
PORTA=0X00;
PORTB=0X00;
UART1_INIT(9600);
delay_ms(100);
while(1){
if(Uart1_data_ready()==1){
uart1_read_text(receive,'F',65);
for(i=0;i<64;i++){
  switch(receive[i]){
      case'1': x=1; break;
      case'0': x=0; break;
  }
 PORTA=x;
 delay_ms(50);
 PORTA=0X00;
 delay_ms(50);
}
   uart1_write('F');
} // end if

}  // end while

}// end main
 

it work without follow the instruction
Means exactly what?

read1_uart_text() may be waiting endlessly for serial data that never comes. Which data is send to the serial input? Char array receive is too small and can overflow, by the way.
 

I wanted to send string code such as binary code to pic and pic will execute if it receive 1 in each block array. I am doing this in purpose to hake CNC 2 axis the binary 1 is the coordinate write.
Please give me more advise!
 

Hi,

Where is your configuration bits initialisation. Can you share that.

Amit
 

what is the configuration bit ? what do you mean? mikroc or VB?
 

Hi,

If you are using MPLAB, you will see in the bottom of the window.

config_bits.png


Check whether WDT is enabled?



Amit
 

It is enabled. Anyway, this code is a bad example of working with UART. Don't share it ))))
 

Or one can also use circular buffer using USART interrupt, it is much more easy than polling for UART_data ready.

- - - Updated - - -

I wanted to send string code such as binary code to pic and pic will execute if it receive 1 in each block array. I am doing this in purpose to hake CNC 2 axis the binary 1 is the coordinate write.
Please give me more advise!

Hi johnny,

Try using this code:

Code:
unsigned short q=0;

void interrupt()
{
if(PIR1.RCIF==1)
{
receive[q]=UART1_Read();//copy byte by byte in receive
q++;
}
}

char  receive[64] ;
void main(){
int x;
int i=0;
TRISA=0X00;
TRISB=0XFF;
TRISC=0X80;
PORTC=0X00;
PORTA=0X00;
PORTB=0X00;
UART1_INIT(9600);
RCIE_bit=1;
INTCON.GIE=1;
PIE1_bit=1;
delay_ms(100);
while(1){

if(q>64)q=0;

if(receive[0]=='0')
{
x=0;
q=0;//resetting q to 0
}

if(receive[1]=='1')
{
x=1;
q=0;
}

 PORTA=x;
 delay_ms(50);
 PORTA=0X00;
 delay_ms(50);
}
   uart1_write('F');
} // end if

}  // end while
 

I used MikroC

- - - Updated - - -

it can not compile in PIE1_bit=1;

what's the problem?


Mrunal Ahirrao
 

Zip and post the complete mikroC project file. I have to see the project settings.
 

The configuration shows WDT disabled. So everything is inside the shown code.

Code:
   Address      Value     Field                                 Category                                                                     Setting                                      

     2007        2F4A   FOSC      Oscillator Selection bits                                            HS oscillator                                                                       
                        WDTE      Watchdog Timer Enable bit                                            WDT disabled                                                                        
                        PWRTE     Power-up Timer Enable bit                                            PWRT disabled                                                                       
                        BOREN     Brown-out Reset Enable bit                                           BOR enabled                                                                         
                        LVP       Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit RB3 is digital I/O, HV on MCLR must be used for programming                         
                        CPD       Data EEPROM Memory Code Protection bit                               Data EEPROM code protection off                                                     
                        WRT       Flash Program Memory Write Enable bits                               Write protection off; all program memory may be written to by EECON control         
                        CP        Flash Program Memory Code Protection bit                             Code protection off
 

I used MikroC

- - - Updated - - -

it can not compile in PIE1_bit=1;

what's the problem?


Mrunal Ahirrao

hi johnny,
Oh, I am sorry it was a typo.try using as easyrider83 suggested, or edit that line with PEIE_bit=1; now it should compile and work. I also use MikroC.
 

what is easyrider83 ?

- - - Updated - - -

The configuration shows WDT disabled. So everything is inside the shown code.

Code:
   Address      Value     Field                                 Category                                                                     Setting                                      

     2007        2F4A   FOSC      Oscillator Selection bits                                            HS oscillator                                                                       
                        WDTE      Watchdog Timer Enable bit                                            WDT disabled                                                                        
                        PWRTE     Power-up Timer Enable bit                                            PWRT disabled                                                                       
                        BOREN     Brown-out Reset Enable bit                                           BOR enabled                                                                         
                        LVP       Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit RB3 is digital I/O, HV on MCLR must be used for programming                         
                        CPD       Data EEPROM Memory Code Protection bit                               Data EEPROM code protection off                                                     
                        WRT       Flash Program Memory Write Enable bits                               Write protection off; all program memory may be written to by EECON control         
                        CP        Flash Program Memory Code Protection bit                             Code protection off
I really don't understand, my setting is the same as shown but it still doesn't work.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top