Forum: Mikrocontroller und Digitale Elektronik (SED1520) Konvertieren von CCS-Code des PIC16F877A auf C18 mit 18F4550


von Andreas G. (beastyk)


Lesenswert?

Hallo,

ich hab hier ein Datavision DG-12232 LCD schon ne ganze Weile rumliegen.
Habe von Geoff Graham seinen Grafiktreiber und die GLCD-Library (sind 
wohl von weiterentwickelte Sachen von Radoslaw Kwiecien).
Der Quellcode ist für den CCS C Compiler und für einen PIC16F877A 
geschrieben. Ich würde das gerne mit dem C18 Microchip Compiler und dem 
PIC18F4550 umsetzen.
(1) Weiß jemand wo ich eine Seite finde die mir aufzeigt welche 
Unteschiede die Compiler in ihrer Syntax haben?

(2) Die beiden PICs werden unterschiedlich angesprochen (wenn ich jetzt 
z.b. die Initialisierung des ADC nehme), wo finde ich für den C18 
Compiler die entsprechenden Befehle etc. (das Datenblatt hat da mehr ASM 
Beispiele drin stehen)
In der p18f4550.h-Datei finde ich die möglichen Befehle (für ADC: 
ADCON0,1,2 mit der Struktur wie im Datenblatt des PIC18F4550 beim 
Unterkapitel ADC).
Ist aber zum verstehen eher kryptisch.
Sehe hier für den 18F4550 auch ein "ADC PERIPHERAL LIBRARY HEADER FILE" 
(adc.h), wo findet man dazu etwas?

Konkret stehen da so im Code für den PIC16F877A Dinge wie:
#device ADC=8
#use fast_io(A)
oder
setup_adc_ports(NO_ANALOGS);    //no analogs for PortA, TRISA?
setup_comparator(NC_NC_NC_NC); //no comperators?

wo ich mal ganz stark davon ausgehe das das bei C18 oder dem 18F4550 
bestimmt nicht durchkommt.
Sondern eher:
ADCON1=0x0f;  // all digital
CMCON=7;    // no comparators

Ich habe die letzten Jahre eher was mit der Hardware zu tun gehabt und 
nun hab ich mir mal das Steckbrett genommen und bin dabei mich in die 
Software reinzufrimmeln. Den USB Bootloader hab ich schon am laufen 
(MCHPUSB).

Das langt erstmal als Hilferuf...ich gebe hier mal den Link zu den oben 
genannten Dateien für den SED1520 an:

http://geoffg.net/SG12232A_Driver.html

Für Tipps und Hilfe bin ich immer dankbar ;o)

Gruß
Andi

von Andreas G. (beastyk)


Lesenswert?

Ich sehe auch gerade das im CCS Compiler die Variable Byte möglich ist, 
ich frage mich wie ich das beim C18 Compiler angehen soll?

von Andreas G. (beastyk)


Lesenswert?

Byte ist ein Datentyp keine Variable und man könnte ihn durch:

typedef char byte;

definieren.

Andreas G. schrieb:
> (2) Die beiden PICs werden unterschiedlich angesprochen (wenn ich jetzt
> z.b. die Initialisierung des ADC nehme), wo finde ich für den C18
> Compiler die entsprechenden Befehle etc. (das Datenblatt hat da mehr ASM
> Beispiele drin stehen)
> In der p18f4550.h-Datei finde ich die möglichen Befehle (für ADC:
> ADCON0,1,2 mit der Struktur wie im Datenblatt des PIC18F4550 beim
> Unterkapitel ADC).
> Ist aber zum verstehen eher kryptisch.
> Sehe hier für den 18F4550 auch ein "ADC PERIPHERAL LIBRARY HEADER FILE"
> (adc.h), wo findet man dazu etwas?

Einfach mal in das PDF "MPLAB_C18_Libraries_51297f" reinschauen!

Gruß
Ich

von Andreas G. (beastyk)


Lesenswert?

Moin Leute,

ich hab neben dem Versuch den Displaytreiber von CSS auf C18 umzusetzen 
auch einfach mal den Displaytreiber mit CSS compiliert und in den 
18F4550 geladen.
Ich habe die SRF angepasst (bitte schaut doch mal ob das so stimmt!).
Das Display blieb allerdings frei von irgendeiner Schrift.
Den Header habe ich natürlich auch geändert...
Nach kurzer Frustration (ich hatte widererwarten doch noch Probs mit dem 
USB) habe ich mir gedacht in die While-Schleife eine LED auf B0 blinken 
zu lassen, das funktioniert soweit auch gut und die ZEit für LED ein und 
aus ist auch ungefähr ne Sekunde.
Ich poste hier mal den Code aus dem Main:
1
/*************************************************************************************************************
2
  SG12232A_Demo.c
3
4
  This is a demonstration of the SG12232A and graphics driver running on a PIC16F877A
5
6
  Version 1.0   Apr 2009
7
8
  Copyright 2009 Geoff Graham - http://geoffg.net
9
  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
10
  Public License as published by the Free Software Foundation, either version 2 of the License, or (at your
11
  option) any later version.
12
13
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
14
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
  for more details.  You should have received a copy of the GNU General Public License along with this program.
16
  If not, see <http://www.gnu.org/licenses/>.
17
  
18
  Development Environment
19
  To compile this you need:
20
   - CCS C Compiler Version 4.0 or higher (www.ccsinfo.com)
21
   - Microchip MPLAB IDE Version 8.0 or higher (www.microchip.com)
22
23
  Caveats:
24
   - It is written for the CCS C compiler
25
   - The 16F877A uses an approx 8MHz clock consisting of a 2.2K resistor and 27pF cap on OSC1 (pin 13)
26
   - The 4KHz clock for the LCD is generated by a never ending loop (not practical in the real world)
27
  
28
  Overworked:
29
     - It is written for the CCS C Compiler
30
   - The 18F4550 uses an external Oscilator with 20 MHz (HS).
31
     - A 2 KHz clock for the Vee on the LCD is generatd by an NE555 on the LCD Platine
32
   - TrisX and PortX Special Function Registers (SFR) settings are changed.
33
34
***************************************************************************************************************/
35
36
#include <18f4550.h>
37
#device ADC=8          // read just 8 bits from the ADC
38
#fuses HSPLL,CPUDIV1,USBDIV,VREGEN,NOPBADEN,WRTB,NOWDT,NOPUT,NOCPD,NOWRT,NOPROTECT,NOBROWNOUT,NOLVP,DEBUG,PLL5,MCLR
39
40
// Clock Related Fuses (select one):
41
//        LP – Low-Power Crystal
42
//        XT – Crystal/Resonator
43
//        HS – High-Speed Crystal/Resonator
44
//        RC – External Resistor-Capacitor (RC) with FOSC/4 output on RA6
45
// Watch Dog Timer:              WDT, NOWDT
46
// Power-up Timer:               PUT,NOPUT
47
// Protect Code:                 PROTECT,NOPROTECT
48
// In-Circuit Debugger Mode:     DEBUG,NODEBUG
49
// Brown-out Detect:             BROWNOUT,NOBROWNOUT
50
// Low-Volt Programming Enable:  LVP, NOLVP
51
// Protect Data Memory:          CPD,NOCPD
52
// Prog mem write protected      WRT_50%,WRT_5%,WRT_25%,NOWRT
53
54
/*************************************************************
55
 ******* Map reset vector and interrupt vector         *******
56
 ******* 0x000-0x7FF is used by the bootloader. The    *******
57
 ******* Bootloader maps the original reset vector (0x000) ***
58
 ******* to 0x800 andthe interrupt vector (0x008) to 0x808 ***
59
 *************************************************************/      
60
61
#build (reset=0x800, interrupt=0x808)
62
63
/*************************************************************
64
 ******* Reserve boot block area             *******
65
 ******* This memory range is used by the bootloader,  *******
66
 ******* so the application could not use this area too ******
67
 ************************************************************/
68
69
#org 0, 0x7FF {}
70
71
/************************************************************/
72
73
74
// processor specific hardware registers - Now for the 18F4550
75
#byte porta = 0xF80            // Port A I/O register
76
#byte portb = 0xF81            // Port A I/O register
77
#byte portd = 0xF83            // Port B I/O register
78
#byte tris_a = 0xF92          // Port A TRIS register
79
#byte tris_b = 0xF93          // Port B TRIS register
80
#byte tris_d = 0xF95          // Port B TRIS register
81
82
#use delay(clock=48000000)
83
84
#use fast_io(A)  
85
#use fast_io(B)
86
#use fast_io(D)
87
  
88
#define TRISA_INIT    0b00000000    // this MUST agree with the #defines below
89
#BIT  LCD_CS2      = porta.0    // output   LCD Chip Select 1
90
#BIT  LCD_CS1      = porta.1    // output   LCD Chip Select 2
91
#BIT   LCD_A0      = porta.2    // output    LCD A0
92
#BIT   LCD_RW      = porta.4    // output   LCD Read/Write
93
  
94
#define TRISB_INIT    0b00000000    // this MUST agree with the #defines below
95
//#BIT   LCD_CLK      = portb.0    // output   LCD Clock (approx 4KHz squarewave)
96
#BIT   LED_B0      = portb.0
97
#BIT   LCD_E      = portb.1    // output   LCD Enable (data strobe)
98
  
99
#BIT   D0      = portd.0    // input & output - Data bus to LCD
100
#BIT   D1      = portd.1    // input & output - Data bus to LCD
101
#BIT   D2      = portd.2    // input & output - Data bus to LCD
102
#BIT   D3      = portd.3    // input & output - Data bus to LCD
103
#BIT   D4      = portd.4    // input & output - Data bus to LCD
104
#BIT   D5      = portd.5    // input & output - Data bus to LCD
105
#BIT   D6      = portd.6    // input & output - Data bus to LCD
106
#BIT   D7      = portd.7    // input & output - Data bus to LCD
107
  
108
#define LCD_DATA     portd      // Data port for the LCD
109
#define LCD_DATA_TRIS    tris_d      // and its associated direction register  
110
111
112
// define some easy to remember types
113
#define bit int1
114
#define int8 signed int8
115
#define uint8 unsigned int8
116
#define int16 signed int16
117
#define uint16 unsigned int16
118
#define int32 signed int32
119
#define uint32 unsigned int32
120
121
/**********************************************************************************************
122
Main program
123
**********************************************************************************************/
124
#include "./SG12232A_Driver_1_0.h"        // this is the LCD driver
125
#include "./glcd_library_1_0.h"        // and this is a universal graphics/fonts package
126
127
void main() {
128
    setup_adc_ports(NO_ANALOGS);
129
  setup_comparator(NC_NC_NC_NC);
130
  SETUP_TIMER_0(RTCC_INTERNAL);
131
  
132
  // set pin directions
133
  tris_a = TRISA_INIT;
134
  tris_b = TRISB_INIT;
135
  
136
  LCD_CS2 = LCD_CS1 = LCD_A0 = 1;
137
  LCD_RW = LCD_E = 0;
138
  
139
  GLCD_Init();          // defined in SG12232A_Driver.h
140
  delay_ms(1000);          // time for Init GLCD
141
  glcd_setxy(0, 0, 1);        // defined in glcd_library.h
142
  printf(glcd_putc916, "Hello World!");    // glcd_putc916 is defined in glcd_library.h
143
  while(1) {
144
    //LCD_CLK = !LCD_CLK;      // generate an approx 4KHz squarewave for the LCD
145
    output_toggle(PIN_B0);      // toggles an LED on B0 on and off
146
      delay_ms(1000);
147
    //delay_us(340);      // delay for 1 sec
148
  }  
149
}

Vielleicht hätte ich bei einigen Ports noch etwas ausschalten müssen mit 
"setup_", bin etwas ideenlos und würde mich über Anregungen freuen!

Gruß
Ich

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.