Coding, Programming, Nerdism

Or maybe I'm a "completely ignorant asshat". Always read the comments but there has been a lot of waves made over Qt since Nokia went kamikaze (IMO going Win on phones is suicide)
 
There's a large cadre of upper management and VP level engineers that can't conceive of how the industry can turn on a dime based on disruptive technology and price points. They don't see that its all coming to about a 2-3yr window for growth->peak->death and that hardware is becoming increasingly irrelevant. So they do the same thing they've always don't build hardware and try to lock it down to a platform. Software is the new hardware.
 
Nokia failed because they let Symbian became stagnant, and it got eclipsed by Android, iOS, and even WP7 (IMO) in terms of usability, customizability, performance, apps/entertainment, etc. - personally, I like WP7, and I think it'll really come into its own with the Mango update this Fall

(finally I can contribute something :D)
 
So glad to be on the administration side of things. Have no patiences for lines and lines of code. The closest thing I get to it now, it either writing security scripts or decompiling virus code
 
I'd ween myself off Qt right the fuck now if I were you.

Not to burst your bubble but a lot of that stuff is from Nokia that just went Microsoft. And honestly, MeeGo was always a piece of shit.

Then again, Swing made me hate Java forever. What a shitty fucking framework.
I got bummed out too when I first heard the about Micro$oft/Nokia deal, but...

Ok, Nokia won't invest in Qt that much anymore, but Qt just got more open through open governance program, so it will be more community driven. It might even be better solution for Qt than before. I any case Qt can't die off - whole KDE is built on it and even if the Nokia desides to sell the whole thing there's a contract that Nokia had to sign (when they bought Qt) that allows KDE to branch the development of Qt anytime they want.

KDE might not be a big profitable corporation like Nokia, but it's great organization to have behind any project.
 
I'm hoping someone can help me out here since we are on the topic of programming. I am working on a class project in my final class that requires us to design an advanced circuit based on our two years of education. I have been designing and in a way try to improve the flexibility in midi communications for guitars/guitar amps. Using micro-controllers (the 8051 to be exact) and C programming, I have managed to come across a fatal error 240 when debugging. After looking up what the 240 code meant I went looking for the section of code that had the error but could not find it. Unfortunately the compiler we use does give locations for syntax errors however will not point out internal process errors which has left me scratching my head as to what could cause the issue. I am thinking it might have to do with the loops, possibly having incorrect parameters.

The program is basically doing exactly what the line 6 FVB4 does that is this thing right here:

350977extraLarge.jpg


The uController is scanning the ports for pushbuttons to be pressed, when it does is sends a serial (saved in the unsigned a through d) signal to the receiving device. Then the program waits on the for the ports trailing edge before the ports are scanned again.

Code:
#include <reg51.h>

void main (void)
{ 
    unsigned x;
    unsigned y;                                               
    
    unsigned a;                                                
    unsigned b;                                                
    unsigned c;                                             
    unsigned d;                                         
    
    a=0x01;
    b=0x02;
    c=0x04;
    d=0x08;
    
    TMOD=0x20;
    TH1=0xFD;
    SCON=0x50;
        
    while(1)
    {
        while(x!=0)                                    
        {
            x=P1;
        }
    
        while(y=0)
        {
            y=0;
            x=P1;
                        
            if (x==0x01)                                   
            {
                TR1=1;
                SBUF=a;
                while(TI==0);
                TI=0;
	        y=y++;
            }
         
            else if (x==0x02)                               
            {
                TR1=1;
                SBUF=b;
                while(TI==0);
                TI=0;
	        y=y++;
            }            
            
            else if (x==0x04)                              
            {
                TR1=1;
                SBUF=c;
                while(TI==0);
                TI=0;
	        y=y++;
            }            
            
            else if (x==0x08)                               
            {
                TR1=1;
                SBUF=d;
                while(TI==0);
                TI=0;
	        y=y++;
            }
        }        
    }    
}
 
Code:
#include <reg51.h>

void main (void)
{ 
    unsigned x;
    unsigned y;                                               
    
    unsigned a;                                                
    unsigned b;                                                
    unsigned c;                                             
    unsigned d;                                         
    
    a=0x01;
    b=0x02;
    c=0x04;
    d=0x08;
    
    TMOD=0x20;
    TH1=0xFD;
    SCON=0x50;
        
    while(1)
    {
        while(x!=0)                                    
        {
            x=P1;
        }
    
        while(y=0)
        {
            y=0;
            x=P1;
                        
            if (x==0x01)                                   
            {
                TR1=1;
                SBUF=a;
                while(TI==0);
                TI=0;
            y=y++;
            }
         
            else if (x==0x02)                               
            {
                TR1=1;
                SBUF=b;
                while(TI==0);
                TI=0;
            y=y++;
            }            
            
            else if (x==0x04)                              
            {
                TR1=1;
                SBUF=c;
                while(TI==0);
                TI=0;
            y=y++;
            }            
            
            else if (x==0x08)                               
            {
                TR1=1;
                SBUF=d;
                while(TI==0);
                TI=0;
            y=y++;
            }
        }        
    }    
}

Either i'm having a bad coding day (hungover) or

while(1) is either a place holder or unnecessary
with the exception of x, y,a,b,c and d, all the variables used in the calculation haven't been defined or initialised
while(y=0), should probably be == instead of = (although you then set y=0 immediately afterwards which is odd seeing as the only way that code will run will be if y is already 0)

edit: also, doing the logical test on x (while(x!=0)) before initialising x could give the wrong result. Some systems auto-initialise to 0.
 
The while(1) is just to keep the desired code rescanned but not the others. I am doing that for time consistency and so that the code is not redefining and reinitializing the variables and timers.

With the while(x!=0), even if the system was auto-initialized to 0 it would just skip that function and move on, it wouldn't give a fatal error 240 on the debug. Changed the while(y=0) to while(y==0), seems to make more sense. I also moved the while(x!=0) after the main string of port scans so that I do not need to initialize the variable x, it has already been done in the previous function

The other "variable" that are undefined are not variables, but physical locations on the microcontroller and are declared in the reg51.h library. The library allows some direct Assembly language to be used within C, so all the variables without definitions are actually assembly commands. I am curious though, if even though I am using a microprocessor only, if I still need #include <stdio.h> as well. I will have to give that a shot.

Unfortunately I do not have access to the computer that has the 8051 compiler and visual basic and codeblocks will not debug the program, so I can't test anything right now.

So now my current source looks like this:

Code:
[B]#include <stdio.h>[/B]
#include <reg51.h>

void main (void)
{ 
    unsigned x;
    unsigned y;                                               
    
    unsigned a;                                                
    unsigned b;                                                
    unsigned c;                                             
    unsigned d;                                         
    
    a=0x01;
    b=0x02;
    c=0x04;
    d=0x08;
    
    TMOD=0x20;
    TH1=0xFD;
    SCON=0x50;
        
    while(1)
    {

	[B]y=0;[/B]                    /* this is made 0 when the code repeats and y=y++ from the previous functions, its just a clearing function */
    
        [B]while(y==0)[/B]
        {

            x=P1;                      /* make the value of x equal the value of Port 1 */
                        
            if (x==0x01)                                   
            {
                TR1=1;               /* turn on the timer */
                SBUF=a;             /* send the variable a to the Serial Buffer */
                while(TI==0);      /* wait for the done bit */
                TI=0;                 /* clear the done bit */
	        y=y++;              /* increment y by one to leave the while function*/
            }
         
            else if (x==0x02)                               
            {
                TR1=1;
                SBUF=b;
                while(TI==0);
                TI=0;
 	        y=y++;
            }            
             
            else if (x==0x04)                              
            {
                TR1=1;
                SBUF=c;
                while(TI==0);
                TI=0;
	        y=y++;
            }            
             
            else if (x==0x08)                               
            {
                TR1=1;
                SBUF=d;
                while(TI==0);
                TI=0;
	        y=y++;
            }
        }

            while(x!=0)                                    
        {
            x=P1;
        }        

    }    
}

EDIT: now looking into it, it would seem that I do need the stdio.h header because it contains the most basic C language functions. I wish we would have been told that when I was learning it. That class was so blah I left not knowing anything, I actually just figured out the C language through looking back at my understanding of Assembly.
 
It doesn't hurt to include extra libraries, only the information needed will end up in the compiled program. I always have stdlib, stdio, math, string and time included, just to be on the safe side.

Now i'm gonna go out on a limb a bit and say that I don't think your approach with the external library isn't going to work, at least not how it's implemented at the moment. My understanding of c is that anything from external libraries is read-only and as such cannot be assigned values.


A much more standard way of achieving what you want is to define functions in the external library and then call them from the main program.

in the external library
Code:
int timer(void){
/*blah blah blah blah timer assembly code*/
return(1);
}

and then in the main program
Code:
win = timer(); /*this activates the timer*/
if(win != 1){
/*we have a problem, the timer wasn't started sucessfully*/
do_something_to_stop_program_breaking();
}

The main thing to remember is that c relies on explicit commands, if you want a routine to happen then you have to call it explicitly. What you were trying to do smacks of c++ and public classes :p

edit: just to clarify, there's nothing wrong with saying x=P1; as you're setting a local variable equal to an external value. take for example "pi" from math.h, to say x=pi; is fine, but pi=x; will throw an error.

edit2: as an aside, it's good practice to use a non-void type for functions (including main) and have a return value. At it's simplest this allows easier debugging of complex programs and allows for much better error detection. As you can probably tell I was taught by a pretty old fashioned programmer who insisted on things being 100% safe at every point, then again he was writing software for Boeing so that's probably a good thing haha