PDA

View Full Version : pls help me convert C to PICBASIC



marcasjr
- 7th December 2008, 07:28
please help me convert this C code to PICBASIC, it is using SPI protocol..


#define MaxSayisi 2

void max6952_putchar(char reg,char data)
{
unsigned char dongu=1;
PORTC.F0 = 0;
for(dongu=1;dongu<=MaxSayisi;dongu++){
SPI_WRITE(reg);
SPI_WRITE(data);
}
PORTC.F0 = 1;
PORTC.F0 = 0;

}

void MAX_6952_init(){

max6952_putchar(0x04,0x01); //Configuration

max6952_putchar(0x01,0x0FF);

max6952_putchar(0x02,0x0FF);

max6952_putchar(0x03,0x01);

}

void main(){

unsigned char dongu=1;
char a[ ]=" ali raza ";
int i;
TRISC=0B00011000;
Spi_Init();
MAX_6952_init();
while(1)
{

for(i=0;i<=10;i++){
max6952_putchar(0x20,a[i]);
max6952_putchar(0x21,a[i+1]);
max6952_putchar(0x22,a[i+2]);
max6952_putchar(0x23,a[i+3]);
delay_ms(500);
}

}

}

this i've done so far...


Device 16F877A
XTAL = 20
ALL_DIGITAL = TRUE
Symbol CS = PORTC.4 ' SPI eeprom CS line
Symbol SCK = PORTC.3 ' Clock pin
Symbol SI = PORTC.5 ' Data in pin
Symbol SO = PORTC.5
Dim reg as BYTE
Dim datas[10] as BYTE
Dim dongu as BYTE

MAX6952_Init:
PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x04]
Shout SI, SCK, MSBFIRST, [0x01]
NEXT
PORTC.0=1
PORTC.0=0

PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x01]
Shout SI, SCK, MSBFIRST, [0xFF]
NEXT
PORTC.0=1
PORTC.0=0

PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x02]
Shout SI, SCK, MSBFIRST, [0xFF]
NEXT
PORTC.0=1
PORTC.0=0

PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x03]
Shout SI, SCK, MSBFIRST, [0x01]
NEXT
PORTC.0=1
PORTC.0=0

Return
max6952_putchar:
PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [reg]
Shout SI, SCK, MSBFIRST, [datas[0]]
NEXT

PORTC.0=1
PORTC.0=0

Return

Main:
TRISC=%010001100
Goto MAX6952_Init
reg=0x20
datas[0]="A"
Goto max6952_putchar
Delayms 500
Goto main


I notice that PORTC.0 is not having output in Proteus when i use my PICBASIC code...

is PORTC.F0 is PORTC.0 in PICBASIC?

excuse me for my wrong grammar...
thanks...

Archangel
- 7th December 2008, 08:19
PBP <>Proteus
PBP != Proteus
Which is to say, PBP code is pretty much useless in Proteus and vice versa. This forum is for M E Labs Pic Basic, I am sure there is a Proteus forum if you check Google. If you get the correct compiler to use , I am sure you can get some help here.
Best Regards,
JS
BTW, your grammar needs no excuse, it is quite acceptable.

marcasjr
- 7th December 2008, 09:03
I use Proton+ PICbasic from Crownhill, I use Proteus ISIS Professional as Simulator...

Archangel
- 7th December 2008, 09:22
I use Proton+ PICbasic from Crownhill, I use Proteus ISIS Professional as Simulator...
Proton <> PBP _ Crownhill sponsors their forum too, and also sells that compiler.
Your Code as posted with my comments in red:


Device 16F877A
XTAL = 20 <font color=red> DEFINE OSC 20</font color>
ALL_DIGITAL = TRUE <font color=red> Not in PBP

The following will work but there are better ways.</font color>
Symbol CS = PORTC.4 ' SPI eeprom CS line
Symbol SCK = PORTC.3 ' Clock pin
Symbol SI = PORTC.5 ' Data in pin
Symbol SO = PORTC.5
<font color=red> Like . . .
CS VAR PortC.4
No Dims in PBP </font color>
Dim reg as BYTE
Dim datas[10] as BYTE
Dim dongu as BYTE
<font color=red> do it this way
Dongu VAR BYTE
Datas VAR BYTE[10]</font color>
MAX6952_Init:
PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x04]
Shout SI, SCK, MSBFIRST, [0x01]
NEXT
PORTC.0=1
PORTC.0=0

PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x01]
Shout SI, SCK, MSBFIRST, [0xFF]
NEXT
PORTC.0=1
PORTC.0=0

PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x02]
Shout SI, SCK, MSBFIRST, [0xFF]
NEXT
PORTC.0=1
PORTC.0=0

PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [0x03]
Shout SI, SCK, MSBFIRST, [0x01]
NEXT
PORTC.0=1
PORTC.0=0

Return
max6952_putchar:
PORTC.0=0
FOR dongu = 1 to 2
Shout SI, SCK, MSBFIRST, [reg]
Shout SI, SCK, MSBFIRST, [datas[0]]
NEXT

PORTC.0=1
PORTC.0=0

Return

Main:
TRISC=%010001100
Goto MAX6952_Init
reg=0x20
datas[0]="A"
Goto max6952_putchar
Delayms 500<font color=red> Nope! Pause 500</font color>
Goto main

That should give you something to chew on a while.

Acetronics2
- 7th December 2008, 09:25
Hi, Marcasjr

You should switch to the other Crownhill forum, if you want to go on with PROTON ...

Alain

Archangel
- 7th December 2008, 09:37
It took me a minute to find it:
http://www.picbasic.org/forum/