Rich, This is normally correct if you write to your bits in different places but = in your case since you write all your bits at once you can use AND and OR mask= s and write directly to the port in one go: const uint8_t outputs_a[4]=3D{ (1<<2) | (1<<6), // Bits 2 and 6 set for A1=3D0, A0=3D0 (1<<3), // Bit 3 set for A1=3D0, A0=3D1 (1<<4), // Bit 4 set for A1=3D1, A0=3D0 (1<<6) // Bit 6 set for A1=3D1, A0=3D1 }; const uint8_t outputs_b[4]=3D{ // Do the same for port b here }; uint8_t temp; while(1){ PORTA=3D(PORTA & 0xA3) | outputs_a[PORTA & 0x03]; PORTB=3D(PORTB & 0xC3) | outports_b[PORTB & 0x03]; } /Ruben > Ruben, > So what I should do is to use a variable to pack the bits in to and > then send that variable to the port! Correct? > Thanks, > rich! > > On 9/13/2015 4:03 AM, Ruben J=F6nsson wrote: > > Hi, > > > > You should be careful here since you can very easily get caught by > > the Read-Modyfy-Write problem (RMW) for short. This can happen when > > you write several individual output bits to a port register very > > close in time after each other. If you have only a couple of tens of > > pF load on the port pins it will fail. In this case I would just > > write the whole port register at once. > > > > > > See here for other sugestions: > > > > > > /Ruben > > > >> Hello all, > >> I solved this problem. Some how I managed to delete everything i= n > >> the XC8 include files. I reinstalled XC8 and that fixed it. Dumb!! Now= I > >> have another problem. The code is running and most of it works > >> correctly. This is about as simple as it gets. I am using a series of = if > >> and elseif statements to check for the setting of two input bits and > >> then set four output bits. It is PortA and B and the input bits are 0 > >> and 1. The two ports control two separate devices. If the setting is 0= , > >> 0 then output bits 2 and 5 are on and bits 3 and 4 are off. If the > >> setting is 0, 1 then bit 2, 4, and 5 are off and bit 3 is on. If the > >> setting is 1, 0 then bits 2, 3, and 5 are off and bit 4 is on. If the > >> setting is 1, 1 then bits 2, 3, and 4 are off and bit 5 is on. That is > >> the way it is supposed to work. So here are three tables showing what = is > >> supposed to happen and what is happening; > >> Supposed to be! The way = it > >> is! Port A The way it is! Port B > >> --------------------------------- ---------------------------------- > >> ---------------------------------- > >> | Input | Output | > >> | Input | Output | | Input | Output | > >> | Bits | Bits | > >> | Bits | Bits | | Bits | > >> Bits | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|-----|------| > >> |-----|-----|-----|-----|-----|------| > >> | 1 | 0 | 2 | 3 | 4 | 6 | 5 for > >> B | 1 | 0 | 2 | 3 | 4 | 6 | | 1 | > >> 0 | 2 | 3 | 4 | 5 | > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|-----|------| > >> |-----|-----|-----|-----|------|-----| > >> | 0 | 0 | 1 | 0 | 0 | 1 | > >> | 0 | 0 | 1 | 0 | 0 | 1 | OK > >> | 0 | 0 | 1 | 0 | 0 | 1 | OK > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> |-----|-----|-----|-----|------|-----| > >> | 0 | 1 | 0 | 1 | 0 | 0 | > >> | 0 | 1 | 0 | 1 | 0 | 0 | OK > >> | 0 | 1 | 1* | 0 | 0 | 1*| Bad* > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> |-----|-----|-----|-----|------|-----| > >> | 1 | 0 | 0 | 0 | 1 | 0 | > >> | 1 | 0 | 0 | 0 | 1* | 0 | OK* > >> | 1 | 0 | 0 | 0 | 1 | 0 | OK > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> |-----|-----|-----|-----|------|-----| > >> | 1 | 1 | 0 | 0 | 0 | 1 | > >> | 1 | 1 | 0 | 0 | 0 | 1 | OK > >> | 1 | 1 | 0 | 1 | 0 | 0 | Bad > >> |-----|-----|-----|-----|-----|-----| > >> |-----|-----|-----|-----|------|-----| > >> |-----|-----|-----|-----|------|-----| > >> > >> As you can see there are problems. The stars mean that even thou= gh > >> there is an ok or a bad this is only true at certain times. On PortA i= f > >> both bits are low and you make bit 1 high the port responds correctly. > >> If both bits are high and you make bit 0 low the output bit climbs fro= m > >> a few mVs to about 100mVs but it never goes to a high condition. On > >> PortB if you have both bits low and you make bit0 high bits 2 and 4 st= ay > >> high. If you have both bits high and you make bit 1 low then bit 2 goe= s > >> low, bit 3 goes high. Also bits 3 and 4 go low. Here is the code: > >> > >> /* > >> * File: Tortoise-Sema2.c > >> * Author: Richard R. Pope > >> * > >> * Created on September 12, 2015, 7:28 AM > >> */ > >> > >> #include > >> #include > >> #include > >> > >> > >> > >> // #pragma config statements should precede project file includes. > >> // Use project enums instead of #define for ON and OFF. > >> > >> // CONFIG > >> #pragma config FOSC =3D INTOSCIO // Oscillator Selection bits > >> //(INTOSC oscillator: I/O function on > >> //RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN) > >> #pragma config WDTE =3D OFF // Watchdog Timer Enable bit (WDT di= sabled) > >> #pragma config PWRTE =3D OFF // Power-up Timer Enable bit (PWRT d= isabled) > >> #pragma config MCLRE =3D OFF // RA5/MCLR/VPP Pin Function Select = bit > >> //(RA5/MCLR/VPP pin function is digital input, MCLR internal= ly > >> //tied to VDD) > >> #pragma config BOREN =3D OFF // Brown-out Detect Enable bit > >> //(BOD disabled) > >> #pragma config LVP =3D OFF // Low-Voltage Programming Enable bi= t > >> //(RB4/PGM pin has digital I/O function, HV on MCLR must be = used > >> //for programming) > >> #pragma config CPD =3D OFF // Data EE Memory Code Protection bi= t > >> //(Data memory code protection off) > >> #pragma config CP =3D OFF // Flash Program Memory Code Protect= ion bit > >> //(Code protection off) > >> > >> /* > >> * > >> */ > >> void main(void) { > >> TRISA0 =3D 1; //RA0 as Input PIN > >> TRISA1 =3D 1; //RA1 as Input PIN > >> TRISA5 =3D 1; //RA5 as Input PIN > >> TRISA7 =3D 1; //RA7 as Input PIN > >> > >> TRISB0 =3D 1; //RB0 as Input PIN > >> TRISB1 =3D 1; //RB1 as Input PIN > >> TRISB6 =3D 1; //RB6 as Input PIN > >> TRISB7 =3D 1; //RB7 as Input PIN > >> > >> PORTA =3D 0; //Set port A outputs to off > >> TRISA2 =3D 0; //RA2 as Output PIN > >> TRISA3 =3D 0; //RA3 as Output PIN > >> TRISA4 =3D 0; //RA4 as Output PIN > >> TRISA6 =3D 0; //RA6 as Output PIN > >> > >> PORTB =3D 0; //Set port B outputs to off > >> TRISB2 =3D 0; //RB2 as Output PIN > >> TRISB3 =3D 0; //RB3 as Output PIN > >> TRISB4 =3D 0; //RB4 as Output PIN > >> TRISB5 =3D 0; //RB5 as Output PIN > >> > >> CMCON =3D 0x07; > >> while(1) > >> { > >> //Set the First signal > >> if (RA0 =3D=3D 0 && RA1 =3D=3D 0) > >> { > >> RA2 =3D 1; //LED1 IS off > >> RA3 =3D 0; //No Grn1 aspect > >> RA4 =3D 0; //No Yel1 aspect > >> RA6 =3D 1; //The Red1 aspect is set > >> } > >> else if (RA0 =3D=3D 1 && RA1 =3D=3D 0) > >> { > >> RA2 =3D 0; //LED1 IS on > >> RA3 =3D 1; //The Grn1 aspect is set > >> RA4 =3D 0; //No Yel1 aspect > >> RA6 =3D 0; //No Red1 aspect > >> } > >> else if (RA0 =3D=3D 0 && RA1 =3D=3D 1) > >> { > >> RA2 =3D 0; //LED1 IS on > >> RA3 =3D 0; //No Grn1 aspect > >> RA4 =3D 1; //The Yel1 aspect is set > >> RA6 =3D 0; //No Red1 aspect > >> } > >> else if (RA0 =3D=3D 1 && RA1 =3D=3D 1) > >> { > >> RA2 =3D 0; //LED1 IS on > >> RA3 =3D 0; //No Grn1 aspect > >> RA4 =3D 0; //No Yel1 aspect > >> RA6 =3D 1; //The Red1 aspect is set > >> } > >> > >> //Set the second signal > >> if (RB0 =3D=3D 0 && RB1 =3D=3D 0) > >> { > >> RB2 =3D 1; //LED1 IS off > >> RB3 =3D 0; //No Grn2 aspect > >> RB4 =3D 0; //No Yel2 aspect > >> RB5 =3D 1; //The Red2 aspect is set > >> } > >> else if (RB0 =3D=3D 1 && RB2 =3D=3D 0) > >> { > >> RB2 =3D 0; //LED2 IS on > >> RB3 =3D 1; //The Grn2 aspect is set > >> RB4 =3D 0; //No Yel2 aspect > >> RB5 =3D 0; //No Red2 aspect > >> } > >> else if (RB0 =3D=3D 0 && RB1 =3D=3D 1) > >> { > >> RB2 =3D 0; //LED2 IS on > >> RB3 =3D 0; //No Grn2 aspect > >> RB4 =3D 1; //The Yel2 aspect is set > >> RB5 =3D 0; //No Red2 aspect > >> } > >> else if (RB0 =3D=3D 1 && RB1 =3D=3D 1) > >> { > >> RB2 =3D 0; //LED2 IS on > >> RB3 =3D 0; //No Grn2 aspect > >> RB4 =3D 0; //No Yel2 aspect > >> RB5 =3D 1; //The Red2 aspect is set > >> } > >> } > >> return; > >> } > >> > >> Any thoughts and help would be great. > >> Thanks, > >> rich! > >> > >> On 9/12/2015 7:48 AM, Richard R. Pope wrote: > >>> Hello all, > >>> Well I was doing pretty good until I went looking for some inc= ludes > >>> for my 628a program. Now I get error messages that the items like > >>> TRISRA0, TrisRB0, and all of the other defined labels for the 628 can= no > >>> longer be found. I have tried starting a new project and I still get = the > >>> same error messages. I am using MPLAB X and the XC8 compiler. Could > >>> someone please help me out with this? I have never had anything like > >>> this happen to me before. I also shut the IDE down and tried to start= a > >>> new project with the same results. > >>> Thanks, > >>> > >> -- > >> Richard R. Pope > >> President > >> Reedsburg Area Model Railroad Club, RAMRC > >> 1230 19th Street #5 > >> Reedsburg, WI 53959 > >> 608-768-7448 > >> mechanic_2@charter.net > >> > >> -- > >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > >> View/change your membership options at > >> http://mailman.mit.edu/mailman/listinfo/piclist > >> > >> > >> ----- > >> No virus found in this message. > >> Checked by AVG - www.avg.com > >> Version: 2015.0.6086 / Virus Database: 4419/10631 - Release Date: 09/1= 3/15 > >> > > > > > > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > > > ----- > No virus found in this message. > Checked by AVG - www.avg.com > Version: 2015.0.6086 / Virus Database: 4419/10631 - Release Date: 09/13/1= 5 > > -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .