New Feature: Syntax Highlighting

Status
Not open for further replies.

ElectroMaster

Administrator
Hi Guys,

I know alot of members have been asking for this, especially in the Microcontrollers forum.

It's really easy to use, simply use the code tag with a language parameter. There are heaps of languages to select:

Code:
[ CODE=c ]
[ CODE=c++ ]
[ CODE=asm ]
[ CODE=basic4gl ]

An example in C:

C:
/* This is a "Hello world" example for the dsPIC30F2020. It will toggle all
*  IO pins on the chip at a rate which is visible from a LED connected to
*  one of the IO pins. It uses the slow internal oscillator so all that is 
*  needed is a 10K pullup resistor on MCLR (pin 1 on a 28 pin DIP chip) and
*  power connected to ALL Vdd, Vss, AVdd, and AVss pins. Don't forget to
*  put some 0.1uF bypass capacitors across the power pins close to the PIC.
*/
 
#include <p30f2020.h>
 
_FOSC(CSW_FSCM_OFF & FRC_LO_RANGE & OSC2_IO); //Oscillator Configuration
_FOSCSEL(FRC); //Oscillator Selection
_FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
_FGS(CODE_PROT_OFF); //Turn off code protect
_FPOR( PWRT_OFF ); //Turn off power up timer

int main(void)
{
 
	unsigned long x;
 
	ADPCFG = 0xffff; //make ADC pins all digital
	TRISA = 0; //Make all PORTs all outputs
	TRISB = 0;
	TRISD = 0;
	TRISE = 0;
	TRISF = 0;
 
	while(1)
	{
		for( x=0; x<100000; x++){;} //Delay apx 200ms
		LATA = ~LATA; //Toggle all bits on ALL ports
		LATB = ~LATB;
		LATD = ~LATD;
		LATE = ~LATE;
		LATF = ~LATF;
	} 
	return 0;
}

Code:
section	.text
    global _start			;must be declared for linker (ld)

_start:					;tell linker entry point

	mov	edx,len	;message length
	mov	ecx,msg	;message to write
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel

	mov	eax,1	;system call number (sys_exit)
	int	0x80	;call kernel

section	.data

msg	db	'Hello, world!',0xa	;our dear string
len	equ	$ - msg			;length of our dear string
 
Testing,
C:
//Write a string to the LCD
void PutMessage(rom char *Message){
char i=0;
    while(Message[i]!=0)
        PutChar(Message[i++]);
} 

void SetPos(unsigned char X,unsigned char Y){
    Xpos=X;
    Ypos=Y;
    if(Y&1)
        X+=0x40;
    if(Y&2)
        X+=Width;
    WriteCommand(0x80+X);    
}

//Set position and write string.
void PutMessageAt(unsigned char X,unsigned char Y,rom char *Message){
char i=0;
    SetPos(X,Y);
    while(Message[i]!=0)
        PutChar(Message[i++]);
}

void PutHex(unsigned int Num,char Digits){
char i;
    Num<<=(4-Digits)*4;
    for(i=0;i<Digits;i++){
        PutNibble((Num>>12)&0x0f);
        Num<<=4;
    }
}

Not sure about yellow on white. Can the colours be changed?

Mike.
 
Just a question...How does this work if I put this

[ CODE = asm ]
movlw 0x5
movwf PORTA
[ /CODE ]


it doesn't seem to work
 
Last edited:
Just a question...How does this work if I put this

Code:
     movlw   0x5
     movwf   PORTA

it doesn't seem to work

Ian, try capitalizing "code" in "
Code:
" and see if it changes anything. That may be it--not sure how EM programmed this thing :D

Der Strom
 
Last edited:
Hi Guys,

Sorry this mod was disabled for the last couple of days due to a bug. It has been fixed and re-enabled.

Regards,
EM
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…