PIC 16f877A problem

Thread Starter

mirrayhan08

Joined Mar 24, 2012
6
Ok about 5 years ago a company came to me with some code to work on, they couldn't find anyone to work on it at all. They tried to fly people in etc... but no luck, lots of talk, very little production. The code was originally written by a IT class and professor as a class project. Runs right about 5000 lines of code. 5 years ago I taught myself the basics and actually managed to make all the changes they wanted. Yea! Me! >>>>TimeWarp 5 years>>>>. Same people contact me about makeing new code for a new device they are working on. All the previous programmers that took the job took the deposit and ran. Can't really blame em because the people I work for are the kind of people who think they know what their doing but don't which makes htem twice as dangerous. Well I accepted the job on salary and the got the assembly code for the old device they need some work on. I try to build the asm and I get all these errors. I comb the code and some idiot was trying to mix C with ASM without declaring anything or that he's gonna write some C code. I filtered that out and it removed all the errors I was having. Now I've got about 200 warning messages saying Operand in not in Bank0 check config bits. Were using the BankSet1 command but its not being recognized anymore.
Heres some code from the BankSet commands.


Rich (BB code):
__CONFIG  _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _LVP_OFF & _DEBUG_OFF & _CPD_OFF

Include File
Rich (BB code):
;Register
PORTA                        EQU     H'0005'
PORTB                        EQU     H'0006'
;Status Bits
RP1                          EQU     H'0006'
RP0                          EQU     H'0005'
;Config Bits
_CP_ALL                      EQU     H'1FFF'
_CP_OFF                      EQU     H'3FFF'
_DEBUG_OFF                   EQU     H'3FFF'
_DEBUG_ON                    EQU     H'37FF'
_WRT_OFF                     EQU     H'3FFF'    ; No prog memmory write protection
_WRT_256                     EQU     H'3DFF'    ; First 256 prog memmory write protected
_WRT_1FOURTH                 EQU     H'3BFF'    ; First quarter prog memmory write protected
_WRT_HALF                    EQU     H'39FF'    ; First half memmory write protected
_CPD_OFF                     EQU     H'3FFF'
_CPD_ON                      EQU     H'3EFF'
_LVP_ON                      EQU     H'3FFF'
_LVP_OFF                     EQU     H'3F7F'
_BODEN_ON                    EQU     H'3FFF'
_BODEN_OFF                   EQU     H'3FBF'
_PWRTE_OFF                   EQU     H'3FFF'
_PWRTE_ON                    EQU     H'3FF7'
_WDT_ON                      EQU     H'3FFF'
_WDT_OFF                     EQU     H'3FFB'
_RC_OSC                      EQU     H'3FFF'
_HS_OSC                      EQU     H'3FFE'
_XT_OSC                      EQU     H'3FFD'
_LP_OSC                      EQU     H'3FFC'
Source
Rich (BB code):
#define  BankSet0        bcf STATUS,RP0 ; Set the RAM bank to 0
#define  BankSet1        bsf STATUS,RP0 ; Set the RAM bank to 1

; Bank-Select Names (for use with BANKSEL directive)
BANK0         EQU     PIR1
BANK1         EQU     PIE1
BANK2         EQU     EEDATA
BANK3         EQU     EECON1
Now the code used to run perfectly with no errors or messages. Now everytime BankSet1 is called. The following commands send messages saying operand not in Bank0. Then it goes back to BankSet0 and no more messages. Then call BankSet1 and the lines after it all give the Bank0 message. Any idea whats causing this? It also won't program anymore. I tried hooking my pk3 up to it pin for pin and it won't detect it. Any ideas?


hello every body,
I need help on my line follower robot based on PIC 16f877A. i download C source code and try to compile this code in MPLAB. but it show missing error in first 6 line. but i can't find any problem those line. i give the code without header file. plz any body find the error or convert it HEX format.
<><><><><><><><><><><><><><><><><><><><><><><><><<>

#include <16F877A.H>; //declare a PIC header
#device adc=8; //set the bit for ADC
#fuses hs, nowdt, noprotect; //set the PIC protection
#use delay (clock=20000000); //set the clock frequency
#byte porta=5; //assign port a
#byte portd=8; //assign port d

int val1; //ADC value 1 left sensor
int val2; //ADC value 2 center sensor
int val3; //ADC value 3 right sensor
int vref; //voltage reference
void lmotor(int gear); //left motor function
void rmotor(int gear); //right motor function


void main() //main function
{
vref=0x7f; //set voltage reference value
set_tris_d(0); //declare port d as output
setup_port_a(all_analog); //enable port a as ADC port
setup_adc(adc_clock_internal); //set the clock for ADC
setup_ccp1(ccp_pwm); //set enable ccp1
setup_ccp2(ccp_pwm); //set enable ccp2
setup_timer_2(t2_div_by_4,100,1); //set post scaler timer

while(1) //inifinite loop
{
portd=0xaa; //set value for motor
set_adc_channel(0); //ADC at port A0 channel
val1=read_adc(); //read and store A0 value
set_adc_channel(2); //ADC at port A2 channel
val2=read_adc(); //read and store A2 value
set_adc_channel(4); //Adc at port A4
val3=read_adc(); //read and store A4 value

//start condition
//if sensor sense dark then value is greater than Vref
//if sensor sense bright then value is lower than Vref
if(val2>vref) //if sensor 2 is dark
{
if((val1<vref)&&(val3<vref)) //sensor 1&3 is bright
{ //send value to motor ccp
lmotor(70); //both motor moving at same rate
rmotor(70);
}
else if (val1>vref) //sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}
else if (val3>vref) //sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
}
else if ((val1>vref)&&(val3<vref)) //if only sensor 1 is dark
{
lmotor(0); //left motor stop
rmotor(70); //right motor move
}





else if ((val3>vref)&&(val1<vref)) //if only sensor 3 is dark
{
lmotor(70); //left motor move
rmotor(0); //right motor stop
}
else //other than condition above
{
lmotor(60); //left motor move slow
rmotor(60); //right motor move slow
}


}
}
//end program
void lmotor(int gear) //left motor ccp control function
{
set_pwm1_duty(gear); //ccp1 duty cycle

}

void rmotor(int gear) //right motor ccp control function
{
set_pwm2_duty(gear); //ccp2 duty cycle
}

<><><><><><><><><><><><><><><><><><><><><><><>

It is very very emargency in my study.

Plz help me very queckly.

Thanks to all

Mehedi.
 

maxpower097

Joined Feb 20, 2009
816
UserPIN is actually stored in an eeprom and theres another one called TEMPpin or something like that, that is in the code. I'm pretty sure the codes gonna work but for some reason I can't program the circuit. I used to use an ICD2 at work and program the boards before they went to assembly. Now I've got that same old ICD2 with no header or CAT5, and a PK3. For some reason the PK3 is saying target not recognized. But when I program my other boards it works fine when there is external power. Does the Pk3 not have enough power to self power a target for programming?

I've tried to pin out my pk3 to match the programming header but the way it was designed I have to pull certain jumpers to put it into programming mode which cuts power to the chip. So should I just grab a cat5 with RJ45 and cut off one end and turn it into an ICD header? Or should I try to find a way to power the chip to program? Do you think the external PK3 app will program it with no power? Is there a setting in MPlab X to tell the pk3 to power the target? Damn I'm rusty at this stuff and my boss is breathing down my neck to get this worked out. Not actually like a real boss but a misquito that keeps biting you.
 

Wendy

Joined Mar 24, 2008
23,429
Welcome to AAC!

A thread belongs to the OP (original poster). Trying to take over someone elses thread is called hijacking, which is not allowed at All About Circuits. I have therefore given you a thread of your very own.

This was split from Pic16LF877a Help with Banks
 

maxpower097

Joined Feb 20, 2009
816
UserPIN is actually stored in an eeprom and theres another one called TEMPpin or something like that, that is in the code. I'm pretty sure the codes gonna work but for some reason I can't program the circuit. I used to use an ICD2 at work and program the boards before they went to assembly. Now I've got that same old ICD2 with no header or CAT5, and a PK3. For some reason the PK3 is saying target not recognized. But when I program my other boards it works fine when there is external power. Does the Pk3 not have enough power to self power a target for programming?
To update my problem MPlab switched settings on the PK3 I forgot or they mixed it up where you gotta go into the PK3 settings, then power tab, tell it to self power target, then actually select the voltage.
 
Top