USB và Pic18F4550

banhatng

Học sinh phổ thông
#62
Minh da sua duoc roi. Sorry may minh khong co Unikey.
bạn có biết lấy dữ liệu từ con pic18 qua usb để vẽ đồ thị lên máy tính không?mình làm theo hướng dẫn của anh Hiền thì được nhưng không hiểu chỗ truyền nhận dữ liệu bằng hid nên không biết lấy thế nào.
bạn có thể liên hệ trao đổi mình qua mail: banhatng@gmail.com
 

lai viet hai

Học sinh phổ thông
#63
help me!! tôi đang làm về pic 18f4550 và màn hình tft, đã thử bằng pic16f thì ok, nhưng qua pic 18f4550 thì nó không lên được, ai đó có thể xem code và giúp tôi được không!
‪#‎include‬ <18f4550.h>
//‪#‎device‬ *=16
#device PASS_STRINGS = IN_RAM
‪#‎FUSES‬ NOWDT //No Watch Dog Timer
#FUSES HSPLL, PLL5, CPUDIV1
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No power Up Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES MCLR //Master clear reset
#FUSES CCP2C1 //Su dung rc1 lam cong OUT PWM
‪#‎use‬ delay(clock=48000000) //Thach anh gan tren board la 20MHz
//#include <string.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <math.h>

‪#‎byte‬ PORTD=0XF83
#byte TRISC=0XF96
#byte TRISD=0XF95
#byte SSPCON=0XFC6
#byte SSPCON2=0XFC5
#byte SSPSTAT=0XFC7
#byte SSPBUF=0XFC9
#byte PORTB=0XF81
#byte TRISB=0XF93

‪#‎define‬ V 128
#define H 160

#define ST7735_NOP 0x00
#define ST7735_SWRESET 0x01
#define ST7735_RDDID 0x04
#define ST7735_RDDST 0x09

#define ST7735_SLPIN 0x10
#define ST7735_SLPOUT 0x11
#define ST7735_PTLON 0x12
#define ST7735_NORON 0x13

#define ST7735_INVOFF 0x20
#define ST7735_INVON 0x21
#define ST7735_DISPOFF 0x28
#define ST7735_DISPON 0x29
#define ST7735_CASET 0x2A
#define ST7735_RASET 0x2B
#define ST7735_RAMWR 0x2C
#define ST7735_RAMRD 0x2E

#define ST7735_PTLAR 0x30
#define ST7735_COLMOD 0x3A
#define ST7735_MADCTL 0x36

#define ST7735_FRMCTR1 0xB1
#define ST7735_FRMCTR2 0xB2
#define ST7735_FRMCTR3 0xB3
#define ST7735_INVCTR 0xB4
#define ST7735_DISSET5 0xB6

#define ST7735_PWCTR1 0xC0
#define ST7735_PWCTR2 0xC1
#define ST7735_PWCTR3 0xC2
#define ST7735_PWCTR4 0xC3
#define ST7735_PWCTR5 0xC4
#define ST7735_VMCTR1 0xC5

#define ST7735_RDID1 0xDA
#define ST7735_RDID2 0xDB
#define ST7735_RDID3 0xDC
#define ST7735_RDID4 0xDD

#define ST7735_PWCTR6 0xFC

#define ST7735_GMCTRP1 0xE0
#define ST7735_GMCTRN1 0xE1

// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x0700
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

#define CS 0b00000001 //Low = select, High = deselect.
#define RE 0b00000010 //High = normal, Low = reset.
#define A0 0b00000100 //Low = Command, High = Data.

const char font[255][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00},
{0x3E, 0x5B, 0x4F, 0x5B, 0x3E},
{0x3E, 0x6B, 0x4F, 0x6B, 0x3E},
{0x1C, 0x3E, 0x7C, 0x3E, 0x1C},
{0x18, 0x3C, 0x7E, 0x3C, 0x18},
{0x1C, 0x57, 0x7D, 0x57, 0x1C},
{0x1C, 0x5E, 0x7F, 0x5E, 0x1C},
{0x00, 0x18, 0x3C, 0x18, 0x00},
{0xFF, 0xE7, 0xC3, 0xE7, 0xFF},
{0x00, 0x18, 0x24, 0x18, 0x00},
{0xFF, 0xE7, 0xDB, 0xE7, 0xFF},
{0x30, 0x48, 0x3A, 0x06, 0x0E},
{0x26, 0x29, 0x79, 0x29, 0x26},
{0x40, 0x7F, 0x05, 0x05, 0x07},
{0x40, 0x7F, 0x05, 0x25, 0x3F},
{0x5A, 0x3C, 0xE7, 0x3C, 0x5A},
{0x7F, 0x3E, 0x1C, 0x1C, 0x08},
{0x08, 0x1C, 0x1C, 0x3E, 0x7F},
{0x14, 0x22, 0x7F, 0x22, 0x14},
{0x5F, 0x5F, 0x00, 0x5F, 0x5F},
{0x06, 0x09, 0x7F, 0x01, 0x7F},
{0x00, 0x66, 0x89, 0x95, 0x6A},
{0x60, 0x60, 0x60, 0x60, 0x60},
{0x94, 0xA2, 0xFF, 0xA2, 0x94},
{0x08, 0x04, 0x7E, 0x04, 0x08},
{0x10, 0x20, 0x7E, 0x20, 0x10},
{0x08, 0x08, 0x2A, 0x1C, 0x08},
{0x08, 0x1C, 0x2A, 0x08, 0x08},
{0x1E, 0x10, 0x10, 0x10, 0x10},
{0x0C, 0x1E, 0x0C, 0x1E, 0x0C},
{0x30, 0x38, 0x3E, 0x38, 0x30},
{0x06, 0x0E, 0x3E, 0x0E, 0x06},
{0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x5F, 0x00, 0x00},
{0x00, 0x07, 0x00, 0x07, 0x00},
{0x14, 0x7F, 0x14, 0x7F, 0x14},
{0x24, 0x2A, 0x7F, 0x2A, 0x12},
{0x23, 0x13, 0x08, 0x64, 0x62},
{0x36, 0x49, 0x56, 0x20, 0x50},
{0x00, 0x08, 0x07, 0x03, 0x00},
{0x00, 0x1C, 0x22, 0x41, 0x00},
{0x00, 0x41, 0x22, 0x1C, 0x00},
{0x2A, 0x1C, 0x7F, 0x1C, 0x2A},
{0x08, 0x08, 0x3E, 0x08, 0x08},
{0x00, 0x80, 0x70, 0x30, 0x00},
{0x08, 0x08, 0x08, 0x08, 0x08},
{0x00, 0x00, 0x60, 0x60, 0x00},
{0x20, 0x10, 0x08, 0x04, 0x02},
{0x3E, 0x51, 0x49, 0x45, 0x3E},
{0x00, 0x42, 0x7F, 0x40, 0x00},
{0x72, 0x49, 0x49, 0x49, 0x46},
{0x21, 0x41, 0x49, 0x4D, 0x33},
{0x18, 0x14, 0x12, 0x7F, 0x10},
{0x27, 0x45, 0x45, 0x45, 0x39},
{0x3C, 0x4A, 0x49, 0x49, 0x31},
{0x41, 0x21, 0x11, 0x09, 0x07},
{0x36, 0x49, 0x49, 0x49, 0x36},
{0x46, 0x49, 0x49, 0x29, 0x1E},
{0x00, 0x00, 0x14, 0x00, 0x00},
{0x00, 0x40, 0x34, 0x00, 0x00},
{0x00, 0x08, 0x14, 0x22, 0x41},
{0x14, 0x14, 0x14, 0x14, 0x14},
{0x00, 0x41, 0x22, 0x14, 0x08},
{0x02, 0x01, 0x59, 0x09, 0x06},
{0x3E, 0x41, 0x5D, 0x59, 0x4E},
{0x7C, 0x12, 0x11, 0x12, 0x7C},
{0x7F, 0x49, 0x49, 0x49, 0x36},
{0x3E, 0x41, 0x41, 0x41, 0x22},
{0x7F, 0x41, 0x41, 0x41, 0x3E},
{0x7F, 0x49, 0x49, 0x49, 0x41},
{0x7F, 0x09, 0x09, 0x09, 0x01},
{0x3E, 0x41, 0x41, 0x51, 0x73},
{0x7F, 0x08, 0x08, 0x08, 0x7F},
{0x00, 0x41, 0x7F, 0x41, 0x00},
{0x20, 0x40, 0x41, 0x3F, 0x01},
{0x7F, 0x08, 0x14, 0x22, 0x41},
{0x7F, 0x40, 0x40, 0x40, 0x40},
{0x7F, 0x02, 0x1C, 0x02, 0x7F},
{0x7F, 0x04, 0x08, 0x10, 0x7F},
{0x3E, 0x41, 0x41, 0x41, 0x3E},
{0x7F, 0x09, 0x09, 0x09, 0x06},
{0x3E, 0x41, 0x51, 0x21, 0x5E},
{0x7F, 0x09, 0x19, 0x29, 0x46},
{0x26, 0x49, 0x49, 0x49, 0x32},
{0x03, 0x01, 0x7F, 0x01, 0x03},
{0x3F, 0x40, 0x40, 0x40, 0x3F},
{0x1F, 0x20, 0x40, 0x20, 0x1F},
{0x3F, 0x40, 0x38, 0x40, 0x3F},
{0x63, 0x14, 0x08, 0x14, 0x63},
{0x03, 0x04, 0x78, 0x04, 0x03},
{0x61, 0x59, 0x49, 0x4D, 0x43},
{0x00, 0x7F, 0x41, 0x41, 0x41},
{0x02, 0x04, 0x08, 0x10, 0x20},
{0x00, 0x41, 0x41, 0x41, 0x7F},
{0x04, 0x02, 0x01, 0x02, 0x04},
{0x40, 0x40, 0x40, 0x40, 0x40},
{0x00, 0x03, 0x07, 0x08, 0x00},
{0x20, 0x54, 0x54, 0x78, 0x40},
{0x7F, 0x28, 0x44, 0x44, 0x38},
{0x38, 0x44, 0x44, 0x44, 0x28},
{0x38, 0x44, 0x44, 0x28, 0x7F},
{0x38, 0x54, 0x54, 0x54, 0x18},
{0x00, 0x08, 0x7E, 0x09, 0x02},
{0x18, 0xA4, 0xA4, 0x9C, 0x78},
{0x7F, 0x08, 0x04, 0x04, 0x78},
{0x00, 0x44, 0x7D, 0x40, 0x00},
{0x20, 0x40, 0x40, 0x3D, 0x00},
{0x7F, 0x10, 0x28, 0x44, 0x00},
{0x00, 0x41, 0x7F, 0x40, 0x00},
{0x7C, 0x04, 0x78, 0x04, 0x78},
{0x7C, 0x08, 0x04, 0x04, 0x78},
{0x38, 0x44, 0x44, 0x44, 0x38},
{0xFC, 0x18, 0x24, 0x24, 0x18},
{0x18, 0x24, 0x24, 0x18, 0xFC},
{0x7C, 0x08, 0x04, 0x04, 0x08},
{0x48, 0x54, 0x54, 0x54, 0x24},
{0x04, 0x04, 0x3F, 0x44, 0x24},
{0x3C, 0x40, 0x40, 0x20, 0x7C},
{0x1C, 0x20, 0x40, 0x20, 0x1C},
{0x3C, 0x40, 0x30, 0x40, 0x3C},
{0x44, 0x28, 0x10, 0x28, 0x44},
{0x4C, 0x90, 0x90, 0x90, 0x7C},
{0x44, 0x64, 0x54, 0x4C, 0x44},
{0x00, 0x08, 0x36, 0x41, 0x00},
{0x00, 0x00, 0x77, 0x00, 0x00},
{0x00, 0x41, 0x36, 0x08, 0x00},
{0x02, 0x01, 0x02, 0x04, 0x02},
{0x3C, 0x26, 0x23, 0x26, 0x3C},
{0x1E, 0xA1, 0xA1, 0x61, 0x12},
{0x3A, 0x40, 0x40, 0x20, 0x7A},
{0x38, 0x54, 0x54, 0x55, 0x59},
{0x21, 0x55, 0x55, 0x79, 0x41},
{0x21, 0x54, 0x54, 0x78, 0x41},
{0x21, 0x55, 0x54, 0x78, 0x40},
{0x20, 0x54, 0x55, 0x79, 0x40},
{0x0C, 0x1E, 0x52, 0x72, 0x12},
{0x39, 0x55, 0x55, 0x55, 0x59},
{0x39, 0x54, 0x54, 0x54, 0x59},
{0x39, 0x55, 0x54, 0x54, 0x58},
{0x00, 0x00, 0x45, 0x7C, 0x41},
{0x00, 0x02, 0x45, 0x7D, 0x42},
{0x00, 0x01, 0x45, 0x7C, 0x40},
{0xF0, 0x29, 0x24, 0x29, 0xF0},
{0xF0, 0x28, 0x25, 0x28, 0xF0},
{0x7C, 0x54, 0x55, 0x45, 0x00},
{0x20, 0x54, 0x54, 0x7C, 0x54},
{0x7C, 0x0A, 0x09, 0x7F, 0x49},
{0x32, 0x49, 0x49, 0x49, 0x32},
{0x32, 0x48, 0x48, 0x48, 0x32},
{0x32, 0x4A, 0x48, 0x48, 0x30},
{0x3A, 0x41, 0x41, 0x21, 0x7A},
{0x3A, 0x42, 0x40, 0x20, 0x78},
{0x00, 0x9D, 0xA0, 0xA0, 0x7D},
{0x39, 0x44, 0x44, 0x44, 0x39},
{0x3D, 0x40, 0x40, 0x40, 0x3D},
{0x3C, 0x24, 0xFF, 0x24, 0x24},
{0x48, 0x7E, 0x49, 0x43, 0x66},
{0x2B, 0x2F, 0xFC, 0x2F, 0x2B},
{0xFF, 0x09, 0x29, 0xF6, 0x20},
{0xC0, 0x88, 0x7E, 0x09, 0x03},
{0x20, 0x54, 0x54, 0x79, 0x41},
{0x00, 0x00, 0x44, 0x7D, 0x41},
{0x30, 0x48, 0x48, 0x4A, 0x32},
{0x38, 0x40, 0x40, 0x22, 0x7A},
{0x00, 0x7A, 0x0A, 0x0A, 0x72},
{0x7D, 0x0D, 0x19, 0x31, 0x7D},
{0x26, 0x29, 0x29, 0x2F, 0x28},
{0x26, 0x29, 0x29, 0x29, 0x26},
{0x30, 0x48, 0x4D, 0x40, 0x20},
{0x38, 0x08, 0x08, 0x08, 0x08},
{0x08, 0x08, 0x08, 0x08, 0x38},
{0x2F, 0x10, 0xC8, 0xAC, 0xBA},
{0x2F, 0x10, 0x28, 0x34, 0xFA},
{0x00, 0x00, 0x7B, 0x00, 0x00},
{0x08, 0x14, 0x2A, 0x14, 0x22},
{0x22, 0x14, 0x2A, 0x14, 0x08},
{0xAA, 0x00, 0x55, 0x00, 0xAA},
{0xAA, 0x55, 0xAA, 0x55, 0xAA},
{0x00, 0x00, 0x00, 0xFF, 0x00},
{0x10, 0x10, 0x10, 0xFF, 0x00},
{0x14, 0x14, 0x14, 0xFF, 0x00},
{0x10, 0x10, 0xFF, 0x00, 0xFF},
{0x10, 0x10, 0xF0, 0x10, 0xF0},
{0x14, 0x14, 0x14, 0xFC, 0x00},
{0x14, 0x14, 0xF7, 0x00, 0xFF},
{0x00, 0x00, 0xFF, 0x00, 0xFF},
{0x14, 0x14, 0xF4, 0x04, 0xFC},
{0x14, 0x14, 0x17, 0x10, 0x1F},
{0x10, 0x10, 0x1F, 0x10, 0x1F},
{0x14, 0x14, 0x14, 0x1F, 0x00},
{0x10, 0x10, 0x10, 0xF0, 0x00},
{0x00, 0x00, 0x00, 0x1F, 0x10},
{0x10, 0x10, 0x10, 0x1F, 0x10},
{0x10, 0x10, 0x10, 0xF0, 0x10},
{0x00, 0x00, 0x00, 0xFF, 0x10},
{0x10, 0x10, 0x10, 0x10, 0x10},
{0x10, 0x10, 0x10, 0xFF, 0x10},
{0x00, 0x00, 0x00, 0xFF, 0x14},
{0x00, 0x00, 0xFF, 0x00, 0xFF},
{0x00, 0x00, 0x1F, 0x10, 0x17},
{0x00, 0x00, 0xFC, 0x04, 0xF4},
{0x14, 0x14, 0x17, 0x10, 0x17},
{0x14, 0x14, 0xF4, 0x04, 0xF4},
{0x00, 0x00, 0xFF, 0x00, 0xF7},
{0x14, 0x14, 0x14, 0x14, 0x14},
{0x14, 0x14, 0xF7, 0x00, 0xF7},
{0x14, 0x14, 0x14, 0x17, 0x14},
{0x10, 0x10, 0x1F, 0x10, 0x1F},
{0x14, 0x14, 0x14, 0xF4, 0x14},
{0x10, 0x10, 0xF0, 0x10, 0xF0},
{0x00, 0x00, 0x1F, 0x10, 0x1F},
{0x00, 0x00, 0x00, 0x1F, 0x14},
{0x00, 0x00, 0x00, 0xFC, 0x14},
{0x00, 0x00, 0xF0, 0x10, 0xF0},
{0x10, 0x10, 0xFF, 0x10, 0xFF},
{0x14, 0x14, 0x14, 0xFF, 0x14},
{0x10, 0x10, 0x10, 0x1F, 0x00},
{0x00, 0x00, 0x00, 0xF0, 0x10},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xF0, 0xF0, 0xF0, 0xF0, 0xF0},
{0xFF, 0xFF, 0xFF, 0x00, 0x00},
{0x00, 0x00, 0x00, 0xFF, 0xFF},
{0x0F, 0x0F, 0x0F, 0x0F, 0x0F},
{0x38, 0x44, 0x44, 0x38, 0x44},
{0x7C, 0x2A, 0x2A, 0x3E, 0x14},
{0x7E, 0x02, 0x02, 0x06, 0x06},
{0x02, 0x7E, 0x02, 0x7E, 0x02},
{0x63, 0x55, 0x49, 0x41, 0x63},
{0x38, 0x44, 0x44, 0x3C, 0x04},
{0x40, 0x7E, 0x20, 0x1E, 0x20},
{0x06, 0x02, 0x7E, 0x02, 0x02},
{0x99, 0xA5, 0xE7, 0xA5, 0x99},
{0x1C, 0x2A, 0x49, 0x2A, 0x1C},
{0x4C, 0x72, 0x01, 0x72, 0x4C},
{0x30, 0x4A, 0x4D, 0x4D, 0x30},
{0x30, 0x48, 0x78, 0x48, 0x30},
{0xBC, 0x62, 0x5A, 0x46, 0x3D},
{0x3E, 0x49, 0x49, 0x49, 0x00},
{0x7E, 0x01, 0x01, 0x01, 0x7E},
{0x2A, 0x2A, 0x2A, 0x2A, 0x2A},
{0x44, 0x44, 0x5F, 0x44, 0x44},
{0x40, 0x51, 0x4A, 0x44, 0x40},
{0x40, 0x44, 0x4A, 0x51, 0x40},
{0x00, 0x00, 0xFF, 0x01, 0x03},
{0xE0, 0x80, 0xFF, 0x00, 0x00},
{0x08, 0x08, 0x6B, 0x6B, 0x08},
{0x36, 0x12, 0x36, 0x24, 0x36},
{0x06, 0x0F, 0x09, 0x0F, 0x06},
{0x00, 0x00, 0x18, 0x18, 0x00},
{0x00, 0x00, 0x10, 0x10, 0x00},
{0x30, 0x40, 0xFF, 0x01, 0x01},
{0x00, 0x1F, 0x01, 0x01, 0x1E},
{0x00, 0x19, 0x1D, 0x17, 0x12},
{0x00, 0x3C, 0x3C, 0x3C, 0x3C},
{0x00, 0x00, 0x00, 0x00, 0x00}
};
int32 de=0,max=0,dem=0,s[15],sl[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int16 count=0;
int8 flag=0;
void delay(int x){
int j;
for(j=0;j<x;j++);
}
void sendcomand(char input){
int j;
PORTD &= ~A0;
PORTD &= ~CS;
SSPBUF = input;
for(j=0;j<1;j++);
PORTD |= CS;
}
void senddata(char input){
int j;
PORTD |= A0;
PORTD &= ~CS;
SSPBUF = input;
for(j=0;j<1;j++);
PORTD |= CS;
}
void SetPix(char x, char y, int color){
char Low = color & 0x00ff;
color >>= 8;
char Hig = color;

sendcomand(ST7735_CASET); // Column addr set
senddata(0x00);
senddata(x); // XSTART
senddata(0x00);
senddata(x+1); // XEND

sendcomand(ST7735_RASET); // Row addr set
senddata(0x00);
senddata(y); // YSTART
senddata(0x00);
senddata(y+1); // YEND

sendcomand(ST7735_RAMWR);

senddata(Low);
senddata(Hig);
}
void clean(int color){
char Low = color & 0x00ff;
color >>= 8;
char Hig = color;

sendcomand(ST7735_CASET); // Column addr set
senddata(0x00);
senddata(0); // XSTART
senddata(0x00);
senddata(V); // XEND

sendcomand(ST7735_RASET); // Row addr set
senddata(0x00);
senddata(0); // YSTART
senddata(0x00);
senddata(H); // YEND

sendcomand(ST7735_RAMWR);
char x,y;
for(x=0;x<V;x++){
for(y=0;y<H;y++){
senddata(Low);
senddata(Hig);
}
}
}
void init(){
PORTD &= ~CS;
delay(0);
PORTD |= RE;
delay(100);
PORTD &= ~RE;
delay(100);
PORTD |= RE;
delay(10000);
sendcomand(ST7735_SWRESET); // 1: Software reset, 0 args, w/delay 150ms 0x01
delay(1000);
sendcomand(ST7735_SLPOUT); // 2: Out of sleep mode, 0 args, w/delay 500ms 0x11
delay(10000);
sendcomand(ST7735_FRMCTR1); // 3: Frame rate ctrl - normal mode) 3 args: 0xb1
senddata(0x01); senddata(0x2C); senddata(0x2D); // Rate = fosc/(1x2+40) * (LINE+2C+2D)
sendcomand(ST7735_FRMCTR2); // 4: Frame rate control - idle mode) 3 args: 0xb2
senddata(0x01); senddata(0x2C); senddata(0x2D); // Rate = fosc/(1x2+40) * (LINE+2C+2D)
sendcomand(ST7735_FRMCTR3); // 5: Frame rate ctrl - partial mode) 6 args: 0xb3
senddata(0x01); senddata(0x2C); senddata(0x2D); // Dot inversion mode
senddata(0x01); senddata(0x2C); senddata(0x2D); // Line inversion mode
sendcomand(ST7735_INVCTR); // 6: Display inversion ctrl) 1 arg) no delay: 0xb4
senddata(0x07); // No inversion
sendcomand(ST7735_PWCTR1); // 7: Power control) 3 args) no delay: 0xc0
senddata(0xA2);
senddata(0x02); // -4.6V
senddata(0x84); // AUTO mode
sendcomand(ST7735_PWCTR2); // 8: Power control) 1 arg) no delay: 0xc1
senddata(0xC5); // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
sendcomand(ST7735_PWCTR3); // 9: Power control) 2 args) no delay: 0xc2
senddata(0x0A); // Opamp current small
senddata(0x00); // Boost frequency
sendcomand(ST7735_PWCTR4); // 10: Power control) 2 args) no delay:
senddata(0x8A); // BCLK/2) Opamp current small & Medium low
senddata(0x2A);
sendcomand(ST7735_PWCTR5); // 11: Power control) 2 args) no delay:
senddata(0x8A); senddata(0xEE);
sendcomand(ST7735_VMCTR1); // 12: Power control) 1 arg) no delay:
senddata(0x0E);
sendcomand(ST7735_INVOFF); // 13: Don't invert display) no args) no delay 0x20
sendcomand(ST7735_MADCTL); // 14: Memory access control (directions)) 1 arg:
senddata(0xC8); // row addr/col addr); bottom to top refresh
sendcomand(ST7735_COLMOD); // 15: set color mode); 1 arg); no delay:
senddata(0x05); // 16-bit color
sendcomand(ST7735_NORON); // 3: Normal display on, no args, w/delay 10ms 0x13
delay(100);
sendcomand(ST7735_DISPON); // 4: Main screen turn on, no args w/delay 100ms 0x29
delay(1000);
}
void ASCII(char x, char y, int color, int background, char letter, char size){
char data,q,z,d,b;
for(q=0;q<5;q++){
data = font[letter][q];
for(z=0;z<8*size;z++){
if((data&1)!=0){
for(d=0; d<size;d++){
for(b=0; b<size;b++){
SetPix(x+(q*size)+d,y+(z*size)+b,color);
}
}
}else{
for(d=0;d<size;d++){
for(b=0;b<size;b++){
SetPix(x+(q*size)+d,y+(z*size)+b,background);
}
}
}
data>>=1;
}
}
}
void prints(char x, char y, int color, int background,char *message, char size){
int j=0;
while(*message){
ASCII(x,y,color,background,*message++, size);
x+=6*size;
if(x>120){
x=0;
y+=8*size;
}
j++;
}
}
void integerprint(char x, char y, int color, int background,int32 integer, char size){
int32 hundredthousands,tenthousands,thousands,hundreds,tens,ones;
hundredthousands=(int32)(integer/100000);
ASCII(x,y,color,background,hundredthousands+48, size);
x+=6;
tenthousands = (int32)(((integer - hundredthousands*100000)) / 10000);
ASCII(x,y,color,background,tenthousands+48, size);
thousands = (int32)((((integer - hundredthousands*100000) -tenthousands*10000)) / 1000);
x+=6;
ASCII(x,y,color,background,thousands+48, size);
hundreds = (int32)(((((integer-hundredthousands*100000) - tenthousands*10000) - thousands*1000)) / 100);
x+=6;
ASCII(x,y,color,background,hundreds+48, size);
tens=(int32)((integer%100)/10);
x+=6;
ASCII(x,y,color,background,tens+48, size);
ones=(int32)integer%10;
x+=6;
ASCII(x,y,color,background,ones+48, size);
}
void box(char x, char y, char high, char breth, int color){
char s,d;
for(s = y; s < y+high; s++){
for(d = x; d < x+breth; d++){
SetPix(d,s,color);
}
}

void main() {

SSPSTAT = 0b01000000;
SSPCON = 0b00100000;
SSPCON2 = 0b00000000;

TRISB = 0b00000100;
TRISC = 0;
TRISD = 0;
//TRISB = 0XFF;

PORTD |= 0b00001000;

init();

clean(BLACK);


while(1){

integerprint(0,100,0xffff,black,123,1);

}
}
 

papa1210

Học sinh phổ thông
#64
Cho em hỏi là em làm mạch theo schematic như hình

Sau khi nạp FW, viết bằng mikroC và cắm vào máy tính thì bị lỗi usb device not recognized trên windows 7
Cho em hỏi cách khắc phục, và có cần cài driver gì trước không ạ
 

truongantn93

Học sinh phổ thông
#65
các bạn cho mình hỏi cái.
mình làm giao tiếp usb với máy tính dùng con 18f4550. code và sơ đò mình lấy trên diễn đàn.và đã làm theo phần cứng như trên.
khi cắm vào máy tính thì nó nhận , nhưng khi kích vào cái check , để sáng led ,nhưng con lứ không sáng.
mình nghi ngờ dây usb quá dài .
vậy các bạn cho mình hỏi khi truyền dữ liệu với usb thì dây dài tầm bao nhiêu l tối đa.
 

Quảng cáo Google